清理URL - 将带有问号的URL重定向301到新URL

时间:2012-08-10 13:34:16

标签: .htaccess redirect seo

原始网址: example.com?file=gallery&d=doc 我想: example.com/gallery.html

我的.htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
RewriteRule ^([^/]*)\.html$ /?file=$1&d=doc [L] 

(从网址中删除了d = doc,因为这不需要)

现在清理网址的工作,但我希望301重定向所有旧网址(?file = example& d = doc )。任何人都可以帮助我.htaccces?现在页面可以从 example.com?file=gallery&d=doc example.com/gallery.html 获得,但应该 example.com/gallery.html

1 个答案:

答案 0 :(得分:2)

试试这个:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.med-pro.pl$
RewriteRule ^(.*)$ http://med-pro.pl/$1 [R=301,L]

RewriteRule ^([^/]*)\.html$ /?plik=$1&d=doc&r=0 [L]

RewriteCond %{QUERY_STRING} ^plik=([^&]*)&d=doc$
RewriteRule .* %1.html? [L,NC,R=301]