我正在尝试隐藏.php文件扩展名,但由于某种原因无法使其正常工作。我最近的尝试是:
<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^folder/([a-zA-Z_\-0-9]+)/?$ /folder/$1.php </IfModule>
我尝试了许多在网上找到的各种代码变体,但仍然没有运气。.htaccess文件位于根目录中。
我用了这个:
RewriteEngine On # Unless directory, remove trailing slash RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L] # Redirect external .php requests to extensionless URL RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/ RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L] # Resolve .php file for extensionless PHP URLs RewriteRule ^([^/.]+)$ $1.php [L]