我有.htaccess
个文件来隐藏.php
个扩展名。当我输入url(localhost,apache)时它确实有效(在浏览器中输入:localhost / project_test)然后它给了我localhost / project_test / login(这是login.php),但是当我想登录时(和重定向到同一目录中名为portal.php的另一个页面)重定向到portal.php不起作用
我的.htaccess
代码:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://localhost/project_test/production/$1 [R=301,L]
RewriteRule ^([^/.]+)$ $1.php [L]
答案 0 :(得分:2)
要从PHP文件中删除.php扩展名,例如yoursite.com/wallpaper.php到yoursite.com/wallpaper,您必须在.htaccess文件中添加以下代码:
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]