apache - .htaccess: Redirect root url to subdirectory, but retain root url -
i in process of cleaning domain's directory structure (woe me setting root url's content in root directory!) , need insight on how use rewriterule correctly.
the gist
i want domain.tld use domain.tld/subdirectory/ still appear domain.tld in url.
my .htaccess far
options +followsymlinks rewriteengine on #force removal of wwww subdomain rewritebase / rewritecond %{http_host} ^www.domain.tld rewriterule ^(.*)$ http://domain.tld/$1 [r=301,l] #trailing slash rewriterule ^/*(.+/)?([^.]*[^/])$ http://%{http_host}/$1$2/ [l,r=301] #redirect root url subdirectory redirectmatch 301 ^/subdirectory/$ http://domain.tld/ rewriterule ^/$ /subdirectory/?$ [l]
the redirectmatch works great. unfortunately, t seems last rewriterule there should work enough, doesn't. old content setup in root directory still appears.
what missing here?
update: resolved
simple fix not experienced enough .htaccess / apache able explain why.
i had:
rewriterule ^/$ /subdirectory/?$ [l]
removing 1 slash fixed everything:
rewriterule ^$ /subdirectory/?$ [l]
so question is: why that?
try this:
rewriteengine on rewritebase / rewritecond %{request_uri} !^/subdirectory/ # rewrites urls # [replace "domain" actual domain, # without tld (.com, .net, .biz, etc)] rewritecond %{http_host} ^(www\.)?domain\. # rewrite subdirectory rewriterule ^(.*)$ /subdirectory/$1 [l]
br spiros
Comments
Post a Comment