Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like to redirect https://mineyourmind.de/forum to https://mineyourmind.net/forum .

Every rewrite rule I could google didn´t work, they also redirected the main domain (mineyourmind.de).

Im redirecting http:// www. and http:// and https:// via the apache siteconfig.

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.mineoyurmind\.de$ [NC]
RewriteRule (.*) https://mienoyurmind.de%{REQUEST_URI} [R=301,L]

The .htaccess of the forum directory looks like this:

ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 500 default

<IfModule mod_rewrite.c>
    RewriteEngine On

    #   If you are having problems with the rewrite rules, remove the "#" from the
    #   line that begins "RewriteBase" below. You will also have to change the path
    #   of the rewrite to reflect the path to your XenForo installation.
    #RewriteBase /xenforo

    #   This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L] 
</IfModule>

Should I add the rewrite for mineyourmind.de/forum to mineyourmind.net/forum to the apache site config or to the htaccess and how should this look like ?


edit:

I tried it like this:

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.mineyourmind\.de$ [NC]
RewriteRule (.*) https://mineyourmind.de%{REQUEST_URI} [R=301,L]
RewriteRule (/forum.*) https://mineyourmind.net/$1 [R=301,L]

and like this

RewriteEngine On
RewriteRule (/forum.*) https://mineyourmind.net/$1 [R=301,L]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.mineyourmind\.de$ [NC]
RewriteRule (.*) https://mineyourmind.de%{REQUEST_URI} [R=301,L]

both isnt working

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Here's a rule to redirect every request that starts with "/forum".

RewriteRule (/forum.*) https://mineyourmind.net/$1 [R=301,L]

This means "when the URI starts with "/forum", you should capture the entire URI and just replace the hostname with mineyourmind.de instead. The $1 means "what you just matched".

Edit:

To make sure that you don't also redirect any file starting with "forum" in its name, you may need two rules.

# To match /forum only:
RewriteRule ^/forum$ https://mineyourmind.net/$1 [R=301,L] 
# To match any URI under the /forum directory, e.g. "/forum/" and "/forum/someotherfile.html"
RewriteRule ^/forum/(.*) https://mineyourmind.net/forum/$1 [R=301,L]

End of edit

Whether you should do this in .htaccess or in the apache site config depends a bit on how your system is set up, i.e. where you store other site-specific documentation. Generally speaking there is a slight overhead when using .htaccess, since apache will re-read the .htaccess file for every new request, whereas site config will only be read when the server is restarted. But as a rule, I would keep all rewrite config together in the same file as far as possible, to make it easier to manage. Whether that is .htacces, or a virtualhost.conf, or httpd.conf, is up to you.

You should also read the RewriteRule documentation, which explains under what circumstances you need to include the initial / in your RewriteRule.

share|improve this answer
    
thank you. so i can just paste it under my other rewrite rules in the apaches site config ? –  user2693017 Sep 6 '13 at 9:43
    
You should always put a specific case before a generic case. If you put this rule under the current redirect, it won't be triggered because the rule matching .* will trigger first so it will never get to /forum. By putting the rule triggered by /forum first, any request that does not match /forum will go on to the next rule and be caught by the .* rule. –  Jenny D Sep 6 '13 at 9:52
    
but this means the other redricts wont work for /forum anymore, right ? –  user2693017 Sep 6 '13 at 10:04
    
Which ones do you mean? If you mean the ones in your .htaccess, they should be in the .htaccess for mineyourmind.net/forum and they will be triggered there. –  Jenny D Sep 6 '13 at 10:17
    
I mean the one in the apaches site config. The one which redirect http and www. to https:// –  user2693017 Sep 6 '13 at 11:26
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.