【问题标题】:.htaccess - make urls like page:part.htaccess - 制作像 page:part 这样的网址
【发布时间】:2013-01-25 16:02:21
【问题描述】:

我有一个发送这些 url 的 .htaccess:

http://example.com/this/is/test/

到 index.php 获取这样的 url:

index.php?var1=this&var2=is&var3=test

我要做的就是将/ 更改为:意味着网址将是这样的:

http://example.com/this:is:test

就像以前一样将变量发送到索引页面。这是我的 .htaccess 文件:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([^/]+)?/?([^/]+)?/?([^/]+)?/?   [NC]
RewriteRule .*     index.php?var1=%1&var2=%2&var3=%3   [L]

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    您不应该使用%{REQUEST_URI} 来匹配零件。因此,为了制作您想要的东西,您必须将您的 / 更改为 :。我也会使用更好的语法。

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/([^:]+):([^:]+):([^/]+)/? index.php?var1=$1&var2=$2&var3=$3 [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-14
      • 2018-04-18
      • 2020-10-11
      • 2016-08-05
      • 2011-10-15
      相关资源
      最近更新 更多