index.php 文件的 .htaccess 重定向

发布于 2024-12-17 06:24:17 字数 758 浏览 0 评论 0原文

我的网站遇到了巨大的重复问题。首先,我将非 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゃ懵逼小萝莉 2024-12-24 06:24:17

达特尼乌斯是对的,但忘了提一件事:正确使用大写(即使不需要,但这始终是一个好习惯):

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

RewriteCond %{REQUEST_URI} !(/admin/index\.php)
RewriteCond %{REQUEST_URI} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L]

请告诉我它是否有效

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):

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

RewriteCond %{REQUEST_URI} !(/admin/index\.php)
RewriteCond %{REQUEST_URI} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L]

Please tell me if it works

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文