htaccess mod_rewrite no duplicate content

社会主义新天地 提交于 2020-01-14 05:41:10

问题


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]

回答1:


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]


来源:https://stackoverflow.com/questions/8292502/htaccess-mod-rewrite-no-duplicate-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!