【发布时间】:2017-01-29 23:36:12
【问题描述】:
我通过domain-A.com访问根目录,通过domain-B.com访问子目录
所有重定向对于domain-B.com 都可以正常工作,除了那些具有same names 的重定向,例如,如果根目录包含一个名为abc.html 的文件并且子目录也包含文件abc.html,在这种情况下访问domain-B.com/abc.html 会显示domain-A.com/abc.html 的内容,但 url 保持不变,即 domain-B.com/abc.html
我想知道如何解决这个问题。 我正在使用 Ubuntu,这些是我为各种文件所做的设置
我已经使用 sudo a2enmod rewrite 启用了 mod_rewrite
.htaccess - 路径 /var/www/html
# Do not change this line.
RewriteEngine on
# Change domain.com to be your primary main domain. http://domain-b.com/
RewriteCond %{HTTP_HOST} ^(www.)?domain-b.com$
# Change 'subfolder' to be the folder you want to redirect request to.
RewriteCond %{REQUEST_URI} !^/domain-b/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subfolder' to be the folder you want to use for your primary domain.
RewriteRule ^(.*)$ /domain-b/$1 [L]
# Change domain.com to be your primary domain again.
# Change 'subfolder' to be the folder you will use for your primary domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?domain-b.com$
RewriteRule ^(/)?$ domain-b/index.html [L]
httpd.conf - 路径 /etc/apache2/conf-available
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
000-default.conf - 路径 /etc/apache2/sites-available
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
000-default.conf - 路径 /etc/apache2/sites-enabled
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
【问题讨论】:
标签: apache .htaccess ubuntu mod-rewrite url-redirection