2017-10-16 77 views
0

我尝试将index.php和系统页面(如404.php,403.php等)重定向到它们各自的.html页面(index.html,404.html,403)。 HTML等)在ROOT目录中。Htaccess将php文件重定向到根目录中的html

问题是,在Stackoverflow上提供的建议解决方案似乎不适用于我的情况。由于技术要求,PHP文件必须保留在根目录中。

规则在.htaccess

RewriteOptions inherit 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ 
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ 
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME}/index.html !-f 
RewriteCond %{REQUEST_FILENAME}/index.php !-f 
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ 
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ 
RewriteRule . index.php [L] 

</IfModule> 
# -- concrete5 urls end -- 

<IfModule mod_headers.c>  
    Header set Access-Control-Allow-Origin * 
</IfModule> 
#Header set Access-Control-Allow-Origin * 

回答

1

在你的主目录.htaccess文件试试这个代码:

RewriteEngine On 
RewriteRule ^(index|404|403)\.php$ /$1.html [L,R=302] 

上面的代码会重定向只提到了在根目录下的网页,如果要添加子目录对其中的任何一个,只需将其更改为像sub/indexsub/404等等。

我适合是好的,改变302301获得永久重定向

+0

这部分的工作。所有内容现在都重定向到index.html。但是,如果我访问php相关子目录(根/文件夹)中的文件夹,它也会重定向到index.html中的根目录,而不是该子目录中的index.php。 – Alex

+0

我确定它只适用于根目录,但你可能在子目录中有其他规则,请稍等我修改它 –

+0

它应该只在根目录下工作,让我知道你是否有.htaccess中的子文件夹或子文件夹中的任何规则 –

相关问题