我原本希望我的网页可以使用和不使用文件扩展名。
这就是我的工作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。我想为Google添加301重定向。
答案 0 :(得分:0)
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>