user691146
user691146

Reputation:

redirect old url to new url

I am facing a problem in redirecting a old url to a new one.

This is the old url: http://www.abc.com/department.asp?dept=Minimal%20cloth

the new url should be: http://www.abc.com/Minimal-cloth

Please suggest me the best possible way

Upvotes: 0

Views: 1465

Answers (3)

Upgradingdave
Upgradingdave

Reputation: 13076

Depending on which modules are enabled in the apache server's config, you can use either mod_alias or mod_rewrite for this. To use mod_alias, use something like

RedirectMatch 301 ^/department\.asp\?dept=(.*) /$1

To use mod_rewrite try something like:

RewriteCond %{QUERY_STRING} ^dept=(.*)$ [NC]
RewriteRule ^/department\.asp/%1 [R=301]

These haven't been tested, but hope they get you started.

Upvotes: 0

anubhava
anubhava

Reputation: 786091

Can you try following rules in your .htaccess file:

Options +FollowSymLinks
RewriteEngine on

# to take care of /department.asp?dept=Minimal%20cloth or 
# /department.asp?dept=Minimal cloth tyoe of URLs
RewriteCond %{QUERY_STRING} ^dept=(.+)(\s|%20)(.+)$ [NC]
RewriteRule ^department\.asp$ /%1-%3? [R=302,L,NC]

# to take care of /department.asp?dept=MinimalCloth type URLs 
RewriteCond %{QUERY_STRING} ^dept=(.+)$ [NC]
RewriteRule ^department\.asp$ /%1? [R=302,L,NC]

Remember RewriteRule doesn't match query string.

Upvotes: 1

mdm
mdm

Reputation: 12630

Apache's mod_rewrite is perfect for this. Excellent tutorial here.

Upvotes: 0

Related Questions