index.php 文件的 .htaccess 重定向
我的网站遇到了巨大的重复问题。首先,我将非 www 重定向到 www 并且工作正常。
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
但我的网站仍然可以通过index.php url访问 为了解决这个问题,我修改为:
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L]
它工作正常,但我遇到 CMS 登录问题,它不允许我登录到我的 CMS。 然后我添加了这个:
RewriteCond %{REQUEST_URI} !^/admin/
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L]
它仍然不允许我登录我的 CMS。我的确切 CMS URL 是:
www.example.com/admin/index.php
I am having huge duplicate issues with my website. First I redirected non-www to www and worked fine.
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
But my website was still accessible through index.php url
To solve that problem I modified as:
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L]
It worked fine but I am having CMS login trouble and it wouldn't let me log in into my CMS.
Then I added this:
RewriteCond %{REQUEST_URI} !^/admin/
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L]
And it still didnt let me login into my CMS. My exact CMS URL is:
www.example.com/admin/index.php
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
达特尼乌斯是对的,但忘了提一件事:正确使用大写(即使不需要,但这始终是一个好习惯):
请告诉我它是否有效
Darthenius is right, but forgot to mention one thing: use uppercase properly (even though it's not needed, it's always a good habit to take):
Please tell me if it works