【发布时间】:2016-02-10 16:12:52
【问题描述】:
我在使用此重定向时遇到了问题。我已经尝试使用 RewriteRule 和 RewriteCond 的 .htaccess 方法,以及 VirtualDirectory 方法。这是我为 VirtualHost 尝试过的:
<VirtualHost *:80>
ServerName blank.example.com
Redirect permanent / "http://example.com/blank/blank"
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster@localhost
DocumentRoot /the/doc/root
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
这对于 .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^blank.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/blank/blank [R=301,L]
我不确定它是否需要,但是 blank.example.com 也指向 /etc/hosts 中的 localhost
关于我缺少什么的任何提示?
【问题讨论】:
-
您是否尝试更改 URL 以使用带有子文件夹的主域而不显示子域?还是要使用浏览器中的子域和子文件夹中的服务器文件?
-
基本上我想把它变成一个 URL 缩短器。所以我真的不在乎它是否显示了它重定向到的完整 URL,但用户需要能够点击较短的链接并到达该重定向的 URL
标签: linux apache .htaccess mod-rewrite