开发者

.htaccess replace parts of the url

开发者 https://www.devze.com 2023-03-12 07:13 出处:网络
I want the htaccess Redirect 301 to do the following: http://mysite.com/article.php?id=123 to htt开发者_开发问答p://mysite.com/123

I want the htaccess Redirect 301 to do the following:

http://mysite.com/article.php?id=123

to

htt开发者_开发问答p://mysite.com/123

Another words, to remove the "article.php?id"part

Any help would be much appreciated.


Use this code in your .htaccess file:

Options +FollowSymlinks -MultiViews
RewriteEngine On

RewriteCond %{QUERY_STRING} ^id=([^&]*)(&|$) [NC]
RewriteRule ^article\.php$ /%1? [L,R=301,NC]

It is important to use ? in the end to get rid of original query string.


You can do this with mod_rewrite if it's enabled:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^article\.php$ http://%{HTTP_HOST}/%1 [L,R=301]
0

精彩评论

暂无评论...
验证码 换一张
取 消