我需要.htaccess文件重定向所有<;任何名称>;。php to<;相同的名称>;。html,但index.php除外
我需要一个.htaccess重写规则,该规则将重定向如下链接:我需要.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
- www.mydomain.com/viewpressrelease.php
- www.mydomain.com/viewpressrelease.php?id=17(或后面的任何文本)
- www.mydomain.com/employment.php
- www.mydomain.com/viewpressrelease.html
- www.mydomain.com/employment.html
- www.mydomain.com/administrator/index.php
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您应该勾选答案旁边的绿色复选标记,这样您的问题就标记为已解决。