Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm cleaning up and rearranging the files on my server (basic shared hosting situation) and am digging into .htaccess to do so. I'm moving the content I had in my web root into the subdirectory of /design/v5/ and am trying to use RewriteRule and RedirectMatch to make the following two scenarios work:

#-------------------------
#Redirect root url to subdirectory
#   1.  Visits: DOMAIN.TLD/*
#       Served: DOMAIN.TLD/design/v5/*
#
#   2.  Visits: DOMAIN.TLD/design/v5/*
#       Redirected: DOMAIN.TLD/*
#-------------------------

RewriteRule ^/(.*)$ /design/v5/$1 [L,R]
RedirectMatch 301 ^/design/v5/(.*)$ /(.*)$1

As you Apache pros can see, I'm mangling something up in a bad way, but am struggling to see where and how (reading through a lot of reference material from similar questions here and other sites at the moment... us designer/front-end guys can be pretty dense).

There are two things that I'd like to accomplish here in addition:

  1. Maintain relative URLs in my coding
  2. Have the redirect/rewrite cascade down into /design/v5/'s own subdirectories.
  3. If I can group those subdirectories together in brackets like (includes|img|scripts|style) or get everything to work with a wildcard instead of writing out separate sets of ReWrite/Redirect rules, that'd be fantastic.
  4. Not have the rewrite effect other subdirectories (ie DOMAIN.TLD/lawlz/imonaboat.gif would still work as written and not being directed from /design/v5/).

As of now, with fiddling to the basic setup I have, I'm getting one of three outcomes:

  1. A blank index directory list of my web root,
  2. A server error page at my web root,
  3. A browser error page from a mangled version of the web root: http://domain.tld/(.)/(.)/(.)/(.)/(.)/(.)...

Late Night Update:

This SO answer works perfectly on the root level, however doesn't redirect away from the subdirectory [when I navigate to DOMAIN.TLD/design/v5, I instead get a redirect to DOMAIN.TLD/(.*)] and mangles up any non-subdomained directories do to the heavy rewrite rule.

RewriteCond %{THE_REQUEST} ^GET\ /design/comingsoon/
RewriteRule ^design/comingsoon/(.*) /$1 [L,R=301]
RewriteRule !^design/comingsoon/ design/comingsoon%{REQUEST_URI} [L]
share|improve this question

migrated from stackoverflow.com Dec 3 '11 at 15:38

This question came from our site for professional and enthusiast programmers.

! is not allow in rewriterule.

RewriteCond %{THE_REQUEST} ^GET\ /design/comingsoon/
RewriteRule ^design/comingsoon/(.*) /$1 [L,R=301]
RewriteRule ^design/comingsoon/ - [L]
#rewrite to '-' doesn't do anything, but with the L flag the rule(s) below it will never be applied
RewriteRule (.*) design/comingsoon/$1 [L]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.