.htaccess Removing ampersand from URL?

佐手、 提交于 2019-12-11 08:39:18

问题


I have been banging my head against a wall for a long time trying to figure out how to get rid of the last part of some of the URL's on my site. For example, I would like to rewrite this:-

http://www.mysite.com/335-protective-wrapping&page=prod

to this

http://www.mysite.com/335-protective-wrapping

There are about 2000 URL's with &page=prod at the end of them which I need to remove. Here's some more example URL's

http://www.mysite.com/335-protective-wrapping&page=prod
http://www.mysite.com/455-bubble-bags&page=prod
http://www.mysite.com/150-specialist-tapes&page=prod

I have tried many solutions but haven't come up with anything that works.

Any help would be much appreciated. Thanks.


回答1:


Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteRule ^([^&]+)&page=prod$ /$1 [L,R=301]



回答2:


This should work:

RedirectMatch 301 ^/(.*)&page=prod$ http://www.mysite.com/$1



回答3:


If you really want to take into account the query part (after the ?) of the source-URI you have to use RewriteCond plus RewriteRule, you cannot just use RewriteRule. (http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond)

Sorry, anubhava, that wont work for that reason.



来源:https://stackoverflow.com/questions/18084513/htaccess-removing-ampersand-from-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!