【问题标题】:URL Mod Rewrite with Region,Country and City使用地区、国家和城市重写 URL Mod
【发布时间】:2014-02-28 07:00:32
【问题描述】:

我正在尝试制定将执行以下操作的重写规则:

http://www.domain.com/index.php?region=europe 重写如下: http://www.domain.com/europe

http://www.domain.com/index.php?region=europe&country=france 重写如下: http://www.domain.com/europe/france

http://www.domain.com/index.php?region=europe&country=france&city=paris 重写如下: http://www.domain.com/europe/france/paris

我完全不知道,尝试了一段时间但没有得到我想要的。

谁能帮助我走向正确的方向?

谢谢!!

【问题讨论】:

    标签: 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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-04-28
        • 2011-10-12
        • 1970-01-01
        • 1970-01-01
        • 2017-09-02
        • 1970-01-01
        • 2015-11-18
        相关资源
        最近更新 更多