: .htaccess rewrite rule domain alias doesn't work I have a site called: www.example.com this is the main domain. Now I have a Alias: www.example2.com. I want that example2.com will be forwarded
I have a site called: example.com this is the main domain. Now I have a Alias: example2.com.
I want that example2.com will be forwarded to a subdomain of the main domain to subdomain.example.com.
I used following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www?example2.com$ [NC]
RewriteRule ^(.*)$ subdomain.example.com/ [R=301,L]
I got an 500 Internal Server Error. And i really don't know why.
More posts by @Sims2060225
1 Comments
Sorted by latest first Latest Oldest Best
As w3d suggested in the comments, you have an open parenthesis, but not one to close it
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www?sek-muenchenstein.ch$ [NC]
# right here -------------^
RewriteRule ^(.*)$ muenchenstein.sek-am.ch/ [R=301,L]
Also, in the COND line, you have www?. I think this might be wrong too, it's now literally looking for the ? in the url, like below, which is highly unlikely:
www?sek-muenchenstein.ch
If you want the alias to redirect, just test without Also also, if you are at siteA.com/example you will end up at siteB.com, without /example.
Code with all suggestions:
RewriteEngine On
RewriteCond %{HTTP_HOST} sek-muenchenstein.ch$ [NC]
RewriteRule ^(.*)$ muenchenstein.sek-am.ch/ [R=301,L]
# Take ------^ and put it ------------------------^^
Or, if you plan ahead and there are multiple alias, reverse the check:
RewriteEngine On
# if not maindomain:
RewriteCond %{HTTP_HOST} !muenchenstein.sek-am.ch$ [NC]
RewriteRule ^(.*)$ muenchenstein.sek-am.ch/ [R=301,L]
Try to make your regexes less detailed. It's easier to read the less you add, and less prone to errors. And changes are less likely to mess things up, eg adding a subdomain. Your code will stop working because of the www, mine wont.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.