【问题标题】:301 redirect index.php?P=301 重定向 index.php?P=
【发布时间】:2018-05-28 09:57:22
【问题描述】:

我有一个从“www.example.com”重定向到“example.com”的网站。使用 .htacccess 文件中的条目:

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

当进入站点:www.example.com,重定向工作:http://example.com

但是,当进入子页面:www.example.com/page1.html,页面加载正确,但是地址是:http://example/index.php?P=page1.html

这和.htaccess文件的入口有关,是从头开始的:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !^(.*)/n_(.*)+ [NC]
RewriteRule ^(.*)?$ index.php?p=$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)/n_(.*)+ [NC]
RewriteRule ^n_(.*)[_+?]?$ index.php?p=news&nid=$1 [QSA,L]

如何处理301重定向删除'index.php? P ='

【问题讨论】:

  • 您需要在内部重写之前执行外部重定向。
  • 还有一个提示:文字点需要在 RegexPatterns 中转义:RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] 通常不需要,但只是偶然或偶然......

标签: php apache .htaccess mod-rewrite


【解决方案1】:

我找到了脚本:

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

对于页面:http://example.com/index.php 返回http://example.com/ 并且工作正常。

子页面有问题:

当他写 http://www.example.com/page.html 时,他得到:http://example.com/?p=page.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-22
    • 1970-01-01
    • 2010-10-27
    • 1970-01-01
    • 1970-01-01
    • 2017-09-17
    • 2015-06-15
    相关资源
    最近更新 更多