繁体   English   中英

mod_rewrite一个双目录

[英]mod_rewrite a double directory

我在我的.htaccess使用mod_rewrite将双目录结构更改为双GET查询字符串,如下所示:

网址: http://domain.com/test/me/http://domain.com/test/me/

在mod_rewrite之后: http://domain.com/index.php?u=test&c=mehttp://domain.com/index.php?u=test&c=me u = test&c = http://domain.com/index.php?u=test&c=me

在我的.htaccess文件中使用以下代码:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/$ /index.php?u=$1&c=$2 [L]

这很好用,但如果没有指定第二个目录(例如http://domain.com/test/ ),我希望c变量等于“all”,如下所示:

http://domain.com/index.php?u=test&c=all

我怎样才能做到这一点? 谢谢 ,正则表达式看起来像克林贡诗歌给我。 我尝试了上述代码的一些不同变体但没有成功。

PS奖励积分,如果您可以添加尾随/即使没有输入到网址框,所以http://domain.com/test/me的处理方式与http://domain.com/test/me/相同http://domain.com/test/me/http://domain.com/test被视为相同http://domain.com/test/

像这样?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)\/?$ index.php?u=$1&c=all
RewriteRule ^([^/]*)/([^/]+)\/?$ index.php?u=$1&c=$2 [L]

还有奖金:P

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM