Ocean Brians
Ocean Brians

Reputation: 1

How to rewrite a URL using mod_rewrite

I am a beginner in url rewriting.

I have a url like this

http://www.sitename.com/subpages/detail.php?id=21-0043-052&car_name=abc

I want to redirect this site to

http://www.qualitextrading.com/vehicle-detail.php?id=21-0043-052&car_name=abc

Please how I can write this in .htaccess file

Upvotes: -1

Views: 44

Answers (1)

Glitch Desire
Glitch Desire

Reputation: 15023

Assuming you have mod_rewrite enabled:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.sitename.com$ [NC]
RewriteRule ^\/subpages\/detail\.php(*.?)$ http://www.qualitextrading.com/vehicle-detail.php$1 [R=301,L]

This turns on rewriting for this area, then checks if the HTTP_HOST is correct, then rewrites the URL and passes on the query string (default behavior of mod_rewrite passes on query string automatically).

Upvotes: 1

Related Questions