Sunday 29 January 2017

.htaccess - 404 issue in two htaccess in root domain and subfoler




My root domain htaccess:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
ErrorDocument 404 /404.php
RewriteCond %{`HTTP_HOST`} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ `https://%1/$1` [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) `https://%{HTTP_HOST}%{REQUEST_URI}` [R=301,L]

In my subfolder htaccess:


RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} `^(www\.example\.com)?$`
RewriteRule ^(.*)$ `https://example.com/subfolder/$1` [R=301,L]



Wehn I type in example.com/any-wrong-url, it will redirect to 404 page, that is correct.




But when I type in example.com/subfoler/any-wrong-url it can not redirect to 404 page. Where do I something wrong?


Answer



The best way to do this without creating any conflict or redirect is:



Use /subfolder/ instead of root / on the RewriteBase like this:



RewriteBase /subfolder/


Copy the 404.php inside the subfolder.




The complete code will look like:



RewriteEngine On
RewriteBase /subfolder/
ErrorDocument 404 /404.php
RewriteCond %{HTTP_HOST} `^(www\.example\.com)?$`
RewriteRule ^(.*)$ `https://example.com/subfolder/$1` [R=301,L]



This should work.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...