开发者

htaccess redirect hostname to FQDN

I have a machine that is local and if you type in http://host it goes to the website on it. I want to use an htaccess to redirect to http://host.domain.com. In the end it is the same I just want to use the proper url for documentation purposes. I tried this but didn't work

   Options +FollowSymlinks
 开发者_运维问答  RewriteEngine on
   rewritecond %{http_host} ^host [nc]
   rewriterule ^(.*)$ http://host.domain.com/$1 [r=301,nc]`


Use the NE flag to keep characters like ? in their raw form instead of turning them into %-escapes, losing their special meaning.

However mod_rewrite is a clumsy way of doing a simple redirect. If you can get access to the main/virtual host config you are better off using Redirect, the tool that was designed for this job:

<VirtualHost *:*>
    ServerName host.domain.com
    ... real host settings...
</VirtualHost>

<VirtualHost *:*>
    ServerName host
    Redirect permanent / http://host.domain.com/
</VirtualHost>


You could try a negative match on the FQDN -so that anything that does not host.domain.com will be redirected to have that.

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} "!^host.domain.com" [nc]
RewriteRule ^(.*)$ http://host.domain.com/$1 [r=301,nc]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜