【问题标题】:URL Mod Rewrite with Region,Country and City使用地区、国家和城市重写 URL Mod
【发布时间】:2014-02-28 07:00:32
【问题描述】:
【问题讨论】:
标签:
apache
.htaccess
mod-rewrite
url-rewriting
【解决方案1】:
将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?region=$1&country=$2&city=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?region=$1&country=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?region=$1 [L,QSA]
【解决方案2】:
RewriteRule ^/(europe)$ index.php?region=$1
RewriteRule ^/(europe)/(france)$ /index.php?region=$1&country=$2
RewriteRule ^/(europe)/(france)/(paris)$ /index.php?region=$1&country=$2&city=$3
使其通用:
RewriteRule ^/([^/]+)$ index.php?region=$1
RewriteRule ^/([^/]+)/([^/]+)$ /index.php?region=$1&country=$2
RewriteRule ^/([^/]+)/([^/]+)/([^/]+)$ /index.php?region=$1&country=$2&city=$3