为什么我的.htacces不起作用?我有页面:
site.com/page.php
我希望看到这样的页面:
site.com/page /
htacces here:
RewriteEngine On
RewriteBase /
RewriteRule /(.*).php /$1
此外,我想看到从page.php重定向到/ page / too
如何?
答案 0 :(得分:1)
您可以在DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteBase /
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]