【发布时间】:2016-10-18 00:25:27
【问题描述】:
如果用户使用“http://example.com/site/”链接到“http://example.com”,我想重定向
我已经搜索并修改了许多示例的 htaccess,但它没有重定向。
我已尝试使用 rewritecond、重定向,但没有按照需要进行重定向。
RewriteCond %{HTTP_HOST} ^https\:\/\/example\.com\/site\/ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
RewriteCond %{REQUEST_URI} !^/site/
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
RewriteCond %{REQUEST_URI} !^/site/.*$
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
RewriteRule ^/site/(.*)$ https://example.com/$1 [L,R=301]
最后我保留了我的 htaccess,如下所示。
HTACCESS代码如下
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
我不知道克服此类问题的可能解决方案。 请帮助我。提前致谢。
【问题讨论】:
-
如果您尝试在不中断文件夹的情况下重写 cond,您可能需要考虑使用
RewriteCond %{REQUEST_FILENAME} !-d
标签: php apache .htaccess redirect mod-rewrite