0

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] 

1 Answer 1

0

! 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] 

You must log in to answer this question.