【问题标题】:URL rewrite with .htaccess and variable sending使用 .htaccess 和变量发送重写 URL
【发布时间】:2014-02-05 13:35:56
【问题描述】:

在我网站的根目录中,我有一个index.php 文件。我希望通过重写所有请求由该文件提供服务。

请求的形式为domain.com/sub1/sub2/.../subx/string,我希望它们由url domain.com/index.php?string 提供服务,其中string 是请求url 的最后一个标记,如果它被/ 分解。

例如

mydomain.com/products/white-shirt/1-20 => mydomain.com/?1-20

提前谢谢你。

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    您可以在 DOCUMENT_ROOT/.htaccess 文件中使用此规则:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (?:^|/)([^/]+)/?$ /?$1 [L,QSA]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-11
      相关资源
      最近更新 更多