Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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文件重定向所有<;任何名称>;。php to<;相同的名称>;。html,但index.php除外_.htaccess_Mod Rewrite_Redirect_Rewrite - Fatal编程技术网

我需要.htaccess文件重定向所有<;任何名称>;。php to<;相同的名称>;。html,但index.php除外

我需要.htaccess文件重定向所有<;任何名称>;。php to<;相同的名称>;。html,但index.php除外,.htaccess,mod-rewrite,redirect,rewrite,.htaccess,Mod Rewrite,Redirect,Rewrite,我需要一个.htaccess重写规则,该规则将重定向如下链接: www.mydomain.com/viewpressrelease.php www.mydomain.com/viewpressrelease.php?id=17(或后面的任何文本) www.mydomain.com/employment.php 要将同名链接替换为.php到.html,请执行以下操作: www.mydomain.com/viewpressrelease.html www.mydomain.com/employ

我需要一个.htaccess重写规则,该规则将重定向如下链接:

  • www.mydomain.com/viewpressrelease.php
  • www.mydomain.com/viewpressrelease.php?id=17(或后面的任何文本)
  • www.mydomain.com/employment.php
要将同名链接替换为.php到.html,请执行以下操作:

  • www.mydomain.com/viewpressrelease.html
  • www.mydomain.com/employment.html
但不要对index.php或以下内容执行操作:

  • www.mydomain.com/administrator/index.php
我有一个很接近的例子,但没有处理?id=17部分,并且正在将index.php转换为index.html

RewriteCond %{THE_REQUEST} ^[A-Z]+\s([^\s]+)\.php\s 
RewriteRule .* %1.html [R=301,L] 
RewriteRule ^(.*)\.html$ $1.php

我需要做什么才能使这项工作符合要求?

您需要添加一个条件来排除
index.php
,然后根据
%{the_REQUEST}
从检查中删除最后一个
\s

RewriteCond %{REQUEST_URI} !index\.php
RewriteCond %{THE_REQUEST} ^[A-Z]+\s([^\s]+)\.php
RewriteRule .* %1.html [R=301,L] 
RewriteRule ^(.*)\.html$ $1.php

谢谢,这似乎完全符合我的需要。@Rassilon您应该勾选答案旁边的绿色复选标记,这样您的问题就标记为已解决。