Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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
Regex .htaccess问题、现有的.php文件和search.php_Regex_.htaccess_Url Rewriting - Fatal编程技术网

Regex .htaccess问题、现有的.php文件和search.php

Regex .htaccess问题、现有的.php文件和search.php,regex,.htaccess,url-rewriting,Regex,.htaccess,Url Rewriting,我对使用.htaccess处理格式良好的URL还不熟悉,我只是不确定我是否做对了 我当前的.htaccess文件如下所示: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^search/(.*) search.php?query=$1 [L] RewriteRule !\.(gif|jpg|ico|css|js|txt|xml|png|swf

我对使用.htaccess处理格式良好的URL还不熟悉,我只是不确定我是否做对了

我当前的.htaccess文件如下所示:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^search/(.*) search.php?query=$1 [L]
RewriteRule !\.(gif|jpg|ico|css|js|txt|xml|png|swf)$ index.php
我想要的是让mysite.com/home/56/page-title转到index.php,在那里我过滤掉数字并加载正确的索引页面,这很好

在此之前,我想检查url是否指向search.php,如果是,则重定向到mysite.com/search/the-search-term,这样也可以

不起作用的是,如果我尝试访问一个特定的.php文件,比如mysite.com/control_panel.php,它只会让我访问index.php,但我认为下面的一行阻止了这种情况的发生

RewriteCond %{REQUEST_FILENAME} !-f
如果有人能向我解释,那就太好了:)


谢谢

1.规则的顺序很重要

2.RewriteCond指令将仅应用于它后面的一个RewriteRule。如果需要对多个规则应用相同的条件,则必须多次编写这些规则或更改重写处理逻辑(有多种方法可用)

试试这个:

RewriteEngine On

RewriteRule ^search/(.*) search.php?query=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(gif|jpg|ico|css|js|txt|xml|png|swf)$ index.php [L]