将嵌套文件夹(子子文件夹)重定向到自己的index.php

问题描述 投票:2回答:1

如何从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>
php apache .htaccess cpanel
1个回答
2
投票

这不需要任何重写规则。只需在.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>
© www.soinside.com 2019 - 2024. All rights reserved.