Reputation: 2028
I want the htaccess Redirect 301 to do the following:
http://mysite.com/article.php?id=123
to
http://mysite.com/123
Another words, to remove the "article.php?id"part
Any help would be much appreciated.
Upvotes: 1
Views: 513
Reputation: 785266
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.
Upvotes: 2
Reputation: 33904
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]
Upvotes: 1