htaccess 删除我网站文件的 .php 扩展名。
RewriteEngine on
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ $1.php [L,QSA]
现在,如果我访问我的网站
www.mysite.com/home
工作正常,它重定向到 home.php 但 URL 仍然友好。
但如果我写这个网址:
www.mysite.com/home.php
home.php 已提供,但 URL 不友好。
我怎样才能避免这种行为?我希望如果用户写 www.mysite.com/home.php,则 URL 栏中显示的 URL 为 www.mysite.com/home
Code
RewriteEngine On
RewriteBase /
# remove enter code here.php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index
RewriteRule (.*)/index$ $1/ [R=301]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)