我想将子域http://app.example.com/
重定向到我的子域http://app.example.com/dashboard/
虽然这看起来很简单。我尝试过的所有东西似乎都没有起作用,我在网上找到的例子要么不起作用,要么不做我需要它做的事。
我也试图从我的根目录开始工作。例如,这是我的归档结构:
/ public_html
/ .htaccess
/ index.php
/ app.example.com
/ dashboard.php
您可以看到我的htaccess文件位于顶层。这是我需要保留的地方。
这是我当前的文件(包括我尝试重定向):
# --------------------------------------------------------------------------------------------------------------------------------------
# Stops people from being able to see htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
# --------------------------------------------------------------------------------------------------------------------------------------
# Options
Options All -Indexes +MultiViews
# --------------------------------------------------------------------------------------------------------------------------------------
# Redirect app.example.com to /dashboard
RewriteEngine On
RewriteCond %{HTTP_HOST} ^app.example.com
RewriteRule ^$ /dashboard [L,R=301]
# --------------------------------------------------------------------------------------------------------------------------------------
# Makes it so url can have slash at the end instead of .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
# --------------------------------------------------------------------------------------------------------------------------------------
# Adds wwww to url if it doesnt already have it
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]