开发者

Apache: Rewrite domain path bug when .htaccess used in non-root dir

开发者 https://www.devze.com 2023-02-10 01:18 出处:网络
How to fix rewrite rule, so that it works also trough domain.com/path/.htaccess? RewriteEngine On RewriteCond %{HTTP_HOST} ^www\\.(.+)$ [NC]

How to fix rewrite rule, so that it works also trough domain.com/path/.htaccess?

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

If rule used in domain.com/.htaccess, redirecting works fine:

www.domain.com/path/url -> domain.com/path/url

If rule used in domain.com/path/.htaccess, redirected incorrect:

www.domain.com/开发者_开发知识库path/url -> domain.com/url // Why not domain.com/path/url ?


%{REQUEST_URI} provides you the full path:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* http://%1%{REQUEST_URI} [R=301,L]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号