I am cleaning up my domain directory structure (woe to me for setting the root URL in the root directory!) And you need to understand how to use the RewriteRule correctly.
The gist
I want domain.tld to use domain.tld / subdirectory /, but still display as domain.tld in the url.
My .htaccess So 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 to subdirectory RedirectMatch 301 ^/subdirectory/$ http://domain.tld/ RewriteRule ^/$ /subdirectory/?$ [L]
RedirectMatch works great. Unfortunately, it seems that the last RewriteRule should work quite simply, but it is not. The old content setting in the root directory still appears.
What am I missing here?
Update: Allowed
A simple fix is ββthat I am not experienced with .htaccess / apache enough to explain why.
I have had:
RewriteRule ^/$ /subdirectory/?$ [L]
Removing one slash fixed everything:
RewriteRule ^$ /subdirectory/?$ [L]
So now my question is: why is this?
source share