Dan
Dan

Reputation: 71

htaccess 301 redirection of urls w/ parameters to url w/o parameters

I would like to do a simple 301 direct on some old URLs that have parameters to them.

e.g.

/dir/page1/?id=4590
/dir/page1/?id=45
/dir2/page5/?id=4590
/dir2/page9/?id=45
/page90/?id=45etc
...

I want a 301 redirect of the above urls to the corresponding urls w/o parameters:

/dir/page1
/dir2/page5
/dir2/page9
/page90

My experience with .htaccess is limited. What would be the simplest and the most correct way to enable the above redirects to actually work.

Upvotes: 0

Views: 169

Answers (1)

anubhava
anubhava

Reputation: 785196

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
RewriteBase /

RewriteCond %{QUERY_STRING} ^id= [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L]

Upvotes: 1

Related Questions