Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.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
htaccess将除一个页面外的所有页面从html重定向到php_Php_Html_.htaccess_Redirect - Fatal编程技术网

htaccess将除一个页面外的所有页面从html重定向到php

htaccess将除一个页面外的所有页面从html重定向到php,php,html,.htaccess,redirect,Php,Html,.htaccess,Redirect,我的网站使用htaccess设置,将所有页面从html定向到php,如下所示: RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^website.com RewriteRule (.*) http://www.website.com/$1 [R=301,L] RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L] 我正在尝试设置雅虎网站浏览器,并验证我的

我的网站使用htaccess设置,将所有页面从html定向到php,如下所示:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^website.com
RewriteRule (.*) http://www.website.com/$1 [R=301,L]

RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
我正在尝试设置雅虎网站浏览器,并验证我的帐户,我需要添加一个元标记或添加一个html文件到我的网站根文件夹。雅虎拒绝承认我的元标签(我确信我添加的是正确的)!因此,我唯一的选择是添加html文件

我的html文件一直被重定向到php,雅虎似乎找不到它


是否可以向我的htaccess文件中添加一些内容,以便除了yahoo需要查看的一个文件之外,所有文件都重定向到php?

尝试添加以下条件:

RewriteCond %{REQUEST_FILENAME} !-f
这应该允许任何实际存在的文件(其他类型的文件还有其他选项)。这假设它不会对已经存在的其他文件造成任何混乱。

我看到了4种主要方法(您可以选择更适合自己的方法-这取决于您的网站重写规则逻辑):

1。添加全局排除规则,以防止对该文件进行任何进一步的重写操作

RewriteCond %{HTTP_HOST} ^website.com
RewriteRule (.*) http://www.website.com/$1 [R=301,L]

# do not do any rewriting to this file
RewriteRule somefile\.html$ - [L]

RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
RewriteCond %{HTTP_HOST} ^website.com
RewriteRule (.*) http://www.website.com/$1 [R=301,L]

# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]

RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
RewriteCond %{REQUEST_URI} !somefile\.html$
RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
如果希望将文件的完整路径指定为更具体的路径(如果有多个文件具有此名称,但位于不同的文件夹中,则仅排除一个特定文件非常有用--此URL应以无前导斜杠开头):

2。添加全局排除规则,以防止对任何现有文件或文件夹进行任何进一步的重写操作

RewriteCond %{HTTP_HOST} ^website.com
RewriteRule (.*) http://www.website.com/$1 [R=301,L]

# do not do any rewriting to this file
RewriteRule somefile\.html$ - [L]

RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
RewriteCond %{HTTP_HOST} ^website.com
RewriteRule (.*) http://www.website.com/$1 [R=301,L]

# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]

RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
RewriteCond %{REQUEST_URI} !somefile\.html$
RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
3。添加将拒绝将此特定.html文件重写为.php的排除条件:

RewriteCond %{HTTP_HOST} ^website.com
RewriteRule (.*) http://www.website.com/$1 [R=301,L]

# do not do any rewriting to this file
RewriteRule somefile\.html$ - [L]

RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
RewriteCond %{HTTP_HOST} ^website.com
RewriteRule (.*) http://www.website.com/$1 [R=301,L]

# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]

RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
RewriteCond %{REQUEST_URI} !somefile\.html$
RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
如果希望将文件的完整路径指定为更具体的路径(如果有多个文件具有此名称,但位于不同的文件夹中,则仅排除一个特定文件非常有用--此URL应以前导斜杠开头):

4。添加排除条件,如果.html文件不存在,则仅允许将.html重写为.php

RewriteCond %{HTTP_HOST} ^website.com
RewriteRule (.*) http://www.website.com/$1 [R=301,L]

# do not do any rewriting to this file
RewriteRule somefile\.html$ - [L]

RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
RewriteCond %{HTTP_HOST} ^website.com
RewriteRule (.*) http://www.website.com/$1 [R=301,L]

# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]

RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
RewriteCond %{REQUEST_URI} !somefile\.html$
RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]

上述所有规则都将放在网站根文件夹的.htaccess中。如果放在其他地方,可能需要一些小的调整。

感谢LDG,这项工作完成了!为了让其他人清楚这个问题,并且不熟悉htaccess,我必须在我的html/php重定向之前加上这一行,然后用灵活的选项给出一个完整的答案。这里的数字4与接受的答案相匹配。