重写规则中的.htaccess'IF'?

时间:2012-05-16 19:26:43

标签: .htaccess

这是我的规则:

RewriteRule ^([^/]+)(/.+)? /negocio$2.php?shopURL=$1 [L,QSA]

如果$2不存在(URL没有两个斜杠),我想回显'/'而不是'.php'。因此条件变为:

RewriteRule ^([^/]+)(/.+)? /negocio/?shopURL=$1 [L,QSA]

我该怎么做或归档相同的结果?

2 个答案:

答案 0 :(得分:1)

很确定这就是RewriteCond的用途!

RewriteEngine on

RewriteCond %{REQUEST_URI} ^/([^/]+)(/.+)$
RewriteRule ^([^/]+)(/.+)? /negocio$2.php?shopURL=$1 [L,QSA]

RewriteCond %{REQUEST_URI} ^/([^/]+)$
RewriteRule ^([^/]+)(/.+)? /negocio/?shopURL=$1 [L,QSA]

答案 1 :(得分:0)

用以下代码替换您的代码:

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/?$ negocio/?shopURL=$1 [L,QSA]

RewriteRule ^([^/]+)(/.+?)/?$ negocio$2.php?shopURL=$1 [L,QSA]
相关问题