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:
- Maintain relative URLs in my coding
- Have the redirect/rewrite cascade down into /design/v5/'s own subdirectories.
- 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.
- 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:
- A blank index directory list of my web root,
- A server error page at my web root,
- 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]
No comments:
Post a Comment