Marsbar
Marsbar

Reputation: 11

htaccess mod_rewrite no duplicate content

I have written a rewrite rule to get all pages looking like

dealer_listings.php?territory=arizona

to be accessible like this

wholesale-parts/arizona/

I would like the ugly url to redirect to the seo friendly one as well.

Options -MultiViews
RewriteEngine on
<FILES .htaccess>  
order allow,deny  
deny from all 
</FILES> 

RewriteRule ^([^/\.]+)/+([^/\.]+)/([^/\.]+)/?$ bussiness_profile.php? what=$1&type=$2&dealer=$3 [L]

rewriterule ^wholesale-parts/([^/\.]+)/?$ dealer_listings.php?territory=$1 [R=301,L]

rewritecond %{http_host} ^www.elite-dealers.com [nc]
rewriterule ^(.*)$ http://elite-dealers.com/$1 [r=301,nc]

RewriteRule ^(([^/]+/)*)index\.php http://elite-dealers.com/$1 [R=301,L]

Upvotes: 0

Views: 267

Answers (1)

Ulrich Palha
Ulrich Palha

Reputation: 9539

Add the following code to your .htaccess file to redirect the ugly URL to the SEO friendly one.

#if the request is for dealer_listings
RewriteCond %{REQUEST_URI} ^/dealer_listings\.php$  [NC]
#and it has a territory parameter
RewriteCond %{QUERY_STRING} ^territory=([^&]+) [NC]
#then 301 redirect to the SEO friendly version
RewriteRule . wholesale-parts/%1/? [L,R=301]

Upvotes: 1

Related Questions