可能的重复:
使用 .htaccess 删除 .php 扩展名 https://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess
我想制作我所有的网站网址,myurl/webpageexamples.php
,重命名为其非扩展版本myurl/webpageexamples
,如果可能的话在.htaccess https://en.wikipedia.org/wiki/.htaccess同时重定向所有流量myurl/webpageexamples.php
到新的myurl/webpageexamples
.
我发现有几个可以从 PHP 重定向到非 PHP,例如:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
我拥有的:
myurl/webpageexamples.php
我想要的是:
myurl/webpageexamples
我希望将 SEO 分数转移到新的myurl/webpageexamples
.
如果实际请求是针对 php 页面,您需要确保进行重定向,并在 URI 缺少 php 时进行内部重写:
RewriteEngine On
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)