.htaccess - 像网页一样制作网址:部分

时间:2013-01-25 16:02:22

标签: .htaccess

我有一个发送这些网址的.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]

1 个答案:

答案 0 :(得分:1)

您不应使用%{REQUEST_URI}来匹配部分。因此,为了实现您的目标,您必须将/更改为:。我还会使用更好的语法。

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