如何从example.com/projects/login
重定向到example.com/projects/login/index.php
?
我的.htaccess:
#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
#Removing .PHP Extension
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# Set XSS Protection header
<IfModule mod_headers.c>
Header set X-XSS-Protection "1; mode=block"
</IfModule>
这不需要任何重写规则。只需在.htaccess顶部使用DirectoryIndex
指令:
DirectoryIndex index.php
RewriteEngine on
#Force www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
#Removing .PHP Extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
# Set XSS Protection header
<IfModule mod_headers.c>
Header set X-XSS-Protection "1; mode=block"
</IfModule>