【发布时间】:2019-04-25 00:56:42
【问题描述】:
我对此束手无策。
我有一个 .htacces 文件,我用它来将某些根目录重定向到文件。
例如:
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?
【问题讨论】:
标签: php apache .htaccess redirect