问题描述:

I'm hosting a forum and have recently decided to move it to a sub-domain instead.

As such, I moved all the forum files in to var/www/forum and I can access the forums just fine through this directory, i.e example.net/forum.

I've also set up the sub-domain in my apache virtual host so that if I go to forum.example.net it will display the forums to me and this also works fine.

All I need to do now is set up a .htaccess to redirect people using the directory URL example.net/forum to forum.example.net.

This answer gets me close, but not quite there as it will continually redirect me.

Ideally I'd like to carry their request over too, e.g example.net/forum/viewtopic.php?example gets redirected to forum.example.net/viewtopic.php?example.

Throughout my search for the answer, mod-rewrite may work but I am not too sure how to implement it.

Any help would be appreciated.

网友答案:

Inside /forum/.htaccess you can use this rule as your first rule:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.net)$ [NC]
RewriteRule ^(.*)$ http://forum.%1/$1 [R=301,L,NE]
网友答案:
RewriteEngine On
RewriteCond "%{HTTP_HOST}" "^www.example.net$" [OR]
RewriteCond "%{HTTP_HOST}" "^example.net$"
RewriteRule ^/?forum/(.*)$ http://forum.example.net/$1 [R=301]
相关阅读:
Top