Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to redirect to .

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

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 (.*){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] 

Should I add the rewrite for to to the apache site config or to the htaccess and how should this look like ?


I tried it like this:

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

and like this

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

both isnt working

share|improve this question
up vote 0 down vote accepted

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

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

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


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$$1 [R=301,L] 
# To match any URI under the /forum directory, e.g. "/forum/" and "/forum/someotherfile.html"
RewriteRule ^/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 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

Your Answer


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.