Reputation: 250
I have multiple sites and domains on my server.
I dont know what am I doing wrong but when I switch directories of my site then in address path is showing up main directory path.
/.htaccess
RewriteEngine On
RewriteBase /
Options -Indexes
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule !^example_home_dir/ /example_home_dir%{REQUEST_URI} [L,NC]
When I'm on home page - everything is ok (example.com is showing content of example_home_dir).
When I manually enter domain with sub directory, then everythink working fine too (example.com/subdir is showing subdir content).
When I click anchor with redirect to "example.com/subdir" then server is redirecting me to "example.com/example_main_dir/subdir" and showing subdir content.
I have tried a lot of solutions and nothing worked.
As a curiosity I will say that redirects in my symfony projects working fine.
I don't know what to do :( Thanks a lot for help.
Upvotes: 1
Views: 31
Reputation: 785481
You may use a redirect rule to strip example_home_dir
from URLs:
DirectorySlash Off
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+example_home_dir/(\S*) [NC]
RewriteRule ^ /%1 [L,NE,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule !^example_home_dir/ example_home_dir%{REQUEST_URI} [L,NC]
Also make sure you always have a trailing slash when you have a URL that points to a directory. So use example.com/subdir/
instead of example.com/subdir
.
Make sure to use a new browser to test this change.
Upvotes: 1