Subdomains rewrite .htaccess

我的未来我决定 提交于 2020-01-06 04:04:11

问题


I have these rules, everything work good.

I just need to add this rule:

from it.domain.org/index.php?city=newyork to it.domain.org/product-usa-newyork

The only thing that change is "newyork". It can be also: lasvegas etc..


回答1:


Try inserting these 2 rules before your existing rules:

#Rewrite from http://it.domain.org/index.php?city=dc to http://it.domain.org/product-usa-dc
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.domain\.org$ [NC]
RewriteCond %{THE_REQUEST} \s/+index\.php\?city=([^\s&]+) [NC]
RewriteRule ^ /product-usa-%1? [R=302,L]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.domain\.org$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^product-usa-([^/]+)/?$ /index.php?city=$1 [L,QSA,NC]



回答2:


Put it at the start

RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTP_HOST} ^[^.]+\.domain\.org$ [NC]
RewriteCond %{THE_REQUEST} \s/+index\.php\?city=([^\s&]+) [NC]
RewriteRule ^ /product-usa-%1 [R=302,L]


来源:https://stackoverflow.com/questions/21889957/subdomains-rewrite-htaccess

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