重定向除了?p = *之外的所有内容

时间:2012-09-12 19:55:34

标签: apache .htaccess mod-rewrite redirect seo

如何配置.htaccess文件以重定向除

之外的所有链接
domain.com?p=*

domain.com/index.php?p=*

到domain.com

我希望你理解我的问题,谢谢你的每一个答案。 来自德国的问候。

1 个答案:

答案 0 :(得分:0)

将它放在文档根目录中的htaccess文件中:

RewriteEngine On

# if query string is p=(something)
RewriteCond %{QUERY_STRING} ^p=
# and request is for "/" or "/index.php"
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{REQUEST_URI} ^/index\.php$
# pass it through, don't do anything
RewriteRule ^ - [L]

# otherwise, redirect everything else to http://domain.com/
RewriteRule ^ http://domain.com/ [L,R=301]