Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress mod_rewrite:if/else类型RewriteRule_Wordpress_.htaccess_Mod Rewrite - Fatal编程技术网

Wordpress mod_rewrite:if/else类型RewriteRule

Wordpress mod_rewrite:if/else类型RewriteRule,wordpress,.htaccess,mod-rewrite,Wordpress,.htaccess,Mod Rewrite,以下重写将以数字4开头的字符串作为变量传递给process.php: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(4[^/]*)$ /process.php?variable=$1 [L] 那么这个 http://www.domain.com/4shopping 映射到 http://www.domain.com/process.php?variable=4shop

以下重写将以数字4开头的字符串作为变量传递给process.php:

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

http://www.domain.com/4shopping
映射到

http://www.domain.com/process.php?variable=4shopping
但我想将最后一条重写规则扩展到基本状态:

if word begins with 4, map to /process.php?variable=$1
else map to /index.php
这句话的第二部分是基本的WordPress重写规则。例如:

http://www.domain.com/shopping
没有4个的将被定向到

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

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^(4[^/]*)$ process.php?variable=$1 [L]
RewriteRule ^([^4/][^/]*)$ index.php?$1 [L]

第一条规则将捕获可以映射到现有文件或目录的任何请求,并将结束重写过程。第二条规则是您的(没有
RewriteCond
条件)。第三条规则将捕获URL路径不以数字开头的任何请求
4

我将在您已有的请求末尾添加两行。其他规则将把尚未转换为process.php的任何内容转换为index.php

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

RewriteCond %{SCRIPT_FILENAME} !process\.php
RewriteRule ^([^/]*)$ index.php?$1
以下是解决方案:

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

我保留了默认的Wordpress规则,并在上面添加了我自己的条件规则,确保在满足条件的情况下终止[L]处理

由于某种原因第三条规则不起作用-即正常的Wordpress URL会导致“找不到文件”错误。使用mod_rewrite的日志功能查看出现了什么问题。请再说一遍,这在原则上是可行的,但不是在和Wordpress玩球