mod_rewrite的:如果/其他类型重写规则 [英] mod_rewrite : if / else type RewriteRule

查看:113
本文介绍了mod_rewrite的:如果/其他类型重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面重写传递一个字符串与4号开始作为一个变量来process.php:

 的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(4 ^ /] *)$ /process.php?variable=$1 [L]
 

所以这个

  http://www.domain.com/4shopping
 

映射到

  http://www.domain.com/process.php?variable=4shopping
 

不过,我想延长这个最后的重写规则,基本状态:

 如果字开头4,映射到/process.php?variable=$1
其他地图的index.php
 

这句话的第二个(人)的部分是基本的单词preSS重写规则。因此,例如:

  http://www.domain.com/shopping
 

已没有4将被引导到

  http://www.domain.com/index.php?shopping(我相信这是道preSS固定链接是如何工作!)
 

解决方案

下面是解决方案:

 重写规则^(4 ^ /] *)$ /feedback.php?sms_$c$c=$1 [L]
#
#BEGIN字preSS
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则。的index.php [L]
#结束字preSS
 

我留在原地默认的Word preSS规则,并加入我自己的条件上面的规则,确保终止[L]处理,如果条件被满足

The following rewrite passes a string starting with the number 4 as a variable to process.php :

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(4[^/]*)$ /process.php?variable=$1 [L]

So this

http://www.domain.com/4shopping

is mapped to

http://www.domain.com/process.php?variable=4shopping

But I want to extend this last rewrite rule to basically state:

if word begins with 4, map to /process.php?variable=$1
else map to /index.php

The second (else) part of this statement is the basic WordPress rewrite rule. So for example:

http://www.domain.com/shopping

which has no 4 will be directed to

http://www.domain.com/index.php?shopping (I believe this is how WordPress permalinks work!)

解决方案

Here's the solution:

RewriteRule ^(4[^/]*)$ /feedback.php?sms_code=$1 [L]
#
# BEGIN wordpress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END wordpress

I left the default Wordpress rules in place, and added my own conditional rule above, making sure to terminate [L] processing if the condition was met

这篇关于mod_rewrite的:如果/其他类型重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆