使用多个值进行 Mod 重写
我正在尝试做这样的事情......不知道我哪里出错了。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)^/(.*)^/(.*)$ /$1/$2.php?page=$3 [L,QSA]
基本上我希望能够放入 /item1/item2/item3 之类的内容并将这些值设置为 $1、$2 和 $3 等......
谢谢
I'm trying to do something like this...Not sure where I am going wrong.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)^/(.*)^/(.*)$ /$1/$2.php?page=$3 [L,QSA]
Basically I want to be able to put in something like /item1/item2/item3 and have those values in $1, $2, and $3 etc....
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用
.+
,而不是.*
。另外请务必考虑可能会有尾部斜杠:Instead of
.*
, try using.+
. Also be sure to consider there may be a trailing slash:在 .htaccess 文件中使用以下代码:
Use following code in your .htaccess file:
http://httpd.apache.org/docs/1.3/mod/mod_rewrite .html#RewriteBase
所以也许你必须设置
RewriteBase
。例如,您可以将其设置为根目录:此外,您不能在模式中使用多个
^
,因为它表示“字符串的起始位置”。http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteBase
So maybe you have to set
RewriteBase
. For example you can set it to the root directory:Also, you can't use more than one
^
in your pattern as it means 'start position of the string'.