문제

I have a subdomain like this:

Example: http://us.example.com/index.php?city=newyork

How do I rewrite to:

http://us.example.com/newyork

"us" is a virtual subdomain. So, It can be different: us, fr, it, etc..

I tried in this way but it does not work

RewriteEngine on

RewriteCond %{HTTP_HOST} !^example\.com
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*) index.php?city=$1
도움이 되었습니까?

해결책

Keep it like this:

RewriteEngine on

# external redirect from actual URL to pretty one
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.example\.com$ [NC]
RewriteCond %{THE_REQUEST} \s/+index\.php\?city=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]

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

EDIT:

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.example\.com$ [NC]
RewriteCond %{THE_REQUEST} \s/+index\.php\?city=([^&]+)&ountry=([^\s&]*)\s [NC]
RewriteRule ^ /%1/%2? [R=302,L]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.example\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?city=$1&country=$2 [L,QSA]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top