【问题标题】:301 redirection from index.php only on main page仅在主页上从 index.php 进行 301 重定向
【发布时间】:2014-09-10 07:46:18
【问题描述】:

我需要将 /index.php 重定向到没有索引但只在主页上的主站点。
我在 htaccess 中使用此代码

RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]

但问题是在管理面板中有路由需要 index.php 才能使页面正常工作。这条规则是每次出现在任何页面上时都会删除 index.php。
我尝试添加这样的行

RewriteCond %{REQUEST_URI} !^/AdminPanel/index\.php.*$

在 RewriteRule 之前,但它不会改变任何东西。
希望你能帮忙。

【问题讨论】:

  • 我在很多方面结合了最后提到的那一行,但我无法让它正常工作。

标签: .htaccess mod-rewrite redirect http-status-code-301


【解决方案1】:

从您的正则表达式中删除 .*

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/index\.php
RewriteRule ^index\.php$ / [R=301,L]

【讨论】:

  • 现在好像可以用了,非常感谢!我会在 10 分钟内将此标记为已接受 :)
猜你喜欢
  • 2013-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-19
  • 2013-02-22
  • 1970-01-01
  • 2015-06-15
相关资源
最近更新 更多