301重定向添加?id =

时间:2014-05-10 17:21:09

标签: .htaccess

我正在尝试将301添加到我的旧脚本中,但是当我添加301时,我希望将旧URL重定向到

http://www.newwebsite.co.uk/new-product.html

但我得到了

http://www.newwebsite.co.uk/new-product.html?id=old-product.html

有什么问题?

下面是我的htaccess文件,你可以看到我已添加到顶部附近的现有代码中的301。

Options +FollowSymlinks

RewriteEngine On

Redirect 301 /old-product.html http://www.newwebsite.co.uk/new-product.html

RewriteCond %{HTTP_HOST} ^websiteone\.co.uk$
RewriteRule ^(.*) http://www.websiteone.co.uk/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^websitetwo\.co.uk$
RewriteRule ^(.*) http://www.websitetwo.co.uk/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^websitethree\.co.uk$
RewriteRule ^(.*) http://www.websitethree.co.uk/$1 [R=301,L]

RewriteCond %{REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|less|pdf|xml)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]

ErrorDocument 404 /notfound.php

#RewriteRule contents/(.*)/(.*)$                            page.php?page_id=$1&url=$2  [NC,L,QSA]

RewriteRule login.html                                          account.php     [NC,L,QSA]

RewriteRule registration.html                               registration.php            [NC,L,QSA]

RewriteRule payment-success.html                        success.php     [NC,L,QSA]

RewriteRule forgotpassword.html                         accountforgotpass.php   [NC,L,QSA]

RewriteRule myprofile.html                                  accountloggedin.php     [NC,L,QSA]

RewriteRule editprofile.html                                accounteditdetails.php  [NC,L,QSA]

RewriteRule shopping-cart.html                          cart.php    [NC,L,QSA]

RewriteRule payment-checkout.html                       checkout.php    [NC,L,QSA]

RewriteRule checkout-password.html                checkoutenterpass.php [NC,L,QSA]

RewriteRule checkout-detail.html                    checkout2.php   [NC,L,QSA]

RewriteRule reset/(.*)/$                                    password_reset.php?vcode=$1 [NC,L,QSA]

RewriteRule (.*)$                                                       include_file.php?id=$1 [NC,L,QSA]    

1 个答案:

答案 0 :(得分:1)

您的重定向由您的重定向行完成;

Redirect 301 /old-product.html http://www.newwebsite.co.uk/new-product.html

...但文件将继续处理。最后一次RewriteRule ......

RewriteRule (.*)$   include_file.php?id=$1 [NC,L,QSA]

...也将捕获相同的URL并重写它。

您可能要做的是将Redirect指令替换为常规RewriteRule;

RewriteCond %{REQUEST_URI} ^/old-product.html [NC]
RewriteRule ^ http://www.newwebsite.co.uk/new-product.html [R=301,L]

...将重定向到新网址并使用L标记来避免处理文件的其余部分。