将根文件夹重定向到文件时,.htaccess文件返回404错误



我对此束手无策。

我有一个.htaces文件,我正在使用它将某些根重定向到文件。

例如:

example.com/example.com/home.php

example.com/subdir/example.com/subdir/home.php

这对我的subdir重定向非常有效,但我的根重定向到home.php会出现404错误,然后将我重定向到我的网站的404 eorr页面。

这是我的.htaccess文件(我把所有东西都放在里面,以防另一条规则把东西扔掉(。

RewriteEngine off
RewriteEngine on
AddDefaultCharset utf-8
#Alter the default time zone for the site
SetEnv TZ Europe/London
#set the RewriteBase
RewriteBase /
#Redirect from root to home.php
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule (/)?$ home.php [L]
#Redirect from /subdir to /subdir/home.php
RewriteCond %{REQUEST_URI} ^/subdir/?$
RewriteRule ^subdir(/)?$ subdir/home.php [L]
#Removing .php from the end of file paths
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA]
#Forcing https://
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI}
#Redirect to 404 error page
ErrorDocument 404 /page_not_found.php
RewriteCond %{HTTP_HOST} ^(www.)?example.com/(.*)$
RewriteRule ^$ "https://example.com/page_not_found.php" [R=301]

我应该怎么做才能让example.com和example.com/重定向到example.com/home.php?

在注释#Removing .php from the end of file paths之后尝试此操作请对自己的代码进行注释并粘贴。它可能会帮助你

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

最新更新