繁体   English   中英

htaccess 301重定向到.html

[英]htaccess 301 redirect to .html

我本来希望页面可以使用文件扩展名,也可以不使用文件扩展名。

这是我的工作htaccess的样子:

RewriteEngine On

# .php to .html
RewriteCond %{THE_REQUEST} \ /(.+)\.php[?\s] [NC]
RewriteRule ^ /%1.html [L,R=301]

# don't need extension on the end
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^(.+)\.html/?$ $1.php [L,NC]

我想扭转以上情况,并强制所有页面解析为.html。 我想包括301 Google重定向。

RewriteEngine  on
RewriteRule ^(.*)$ $1.php

例如,这将正确重写example.com/test作为对example.com/test.php的请求

您可以通过以下代码删除两个php html扩展名

<IfModule mod_rewrite.c>
Options +MultiViews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
#RewriteRule ^([a-z]+)\/?$ $1.php [NC]


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
#RewriteRule ^([a-z]+)\/?$ $1.html [NC]

</IfModule>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM