Redirect Syntax

I am using


Redirect 301 / http://mysite.com

What I want to do is redirect www.mysite.com to mysite.com and also several other names such as www.myothersite.com or myothersite.com to mysite.com.

Is this the best way to do this? Also, it’s not working at this point, do I have a syntax error?

No, Redirect can not modify requests. It can for example not strip ‘www’ from an URL. To do that you need mod_rewrite. For the two examples:


Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\\.mysite\\.com$ [NC]
RewriteCond .? http://mysite.com%{REQUEST_URI} [L,R=301]


RewriteCond %{HTTP_HOST} myothersite\\.com$ [NC]
RewriteCond .? http://mysite.com%{REQUEST_URI} [L,R=301]

If you any questions, ask away.

HTH :slight_smile:

Here is what I have in there now and it gives me a 500 Internal Server Error when I enter http://www.mysite.com


AddHandler php5-script .php

Options +FollowSymLinks -Indexes -MultiViews

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\\.mysite\\.com$ [NC]
RewriteCond .? http://mysite.com%{REQUEST_URI} [L,R=301]

It does redirect it to http://mysite.com however

Never mind on that one. If I change the second line to RewriteRule it works fine to remove the www. :slight_smile:

But if I put this in it doesn’t work for myothersite. Is it a syntax error or do I have a problem at my web hoster?


RewriteCond %{HTTP_HOST} ^www\\.mysite\\.com$ [NC]
RewriteCond %{HTTP_HOST} myothersite\\.com$ [NC]
RewriteRule .? http://mysite.com%{REQUEST_URI} [L,R=301]

Also tried the ^ in front on line 2 and that doesn’t work either


RewriteCond %{HTTP_HOST} ^www\\.mysite\\.com$ [NC]
RewriteCond %{HTTP_HOST} ^myothersite\\.com$ [NC]
RewriteRule .? http://mysite.com%{REQUEST_URI} [L,R=301]

Also, is there a way to make this for any address that gets pointed to this site that I want it to go to http://mysite.com

So if any of the following are pointed to this IP address, it will go to that address:


www.mysite.com
mysite.com
myothersite.com
www.myothersite.com
www.mynextsite.com
www.whateversite.com
whateversite.com

Quick update. I finally figured out that since I am using a virtual hosting environment, I have to put an htaccess file in the myothersite.com root directory for this to work.

Did that and switched back to


Redirect 301 / http://mysite.com/

and all seems to work fine. Is it okay to use Redirect in this situation?

I’ve never seen it used in a situation like this, but if it works for you I don’t see why not :slight_smile:

The drawback is that this will always redirect back to the root of your site, so if someone requests [noparse]http://myothersite.com/some/path[/noparse] they will be redirected to [noparse]http://mysite.com/[/noparse] and not to [noparse]http://mysite.com/some/path[/noparse].
Using mod_rewrite you could do that, but if you’re okay with rewriting everything to the root than that should be fine too.
(Although I’m not sure of the SEO impact of doing that, you might want to ask in the SEO forum).

Actually it does redirect with the additional qualifiers. So if I just type myothersite.com/About_Us it redirects to mysite.com/About_Us

Is it not supposed to be doing that or am I missing something?

Regarding the SEO, I will look into that. Good point and thanks.

Sounds like it’s time for me to read up on Alias eh? :wink:
Apparently ot works differently than I thought it did …

I just played with it a little bit and without the trailing “/” it only works if you enter myothersite.com. If you put anything after that like myothersite.com/About it will redirect to mysite.comAbout which obviously can’t be found.

But with the slash in there it seems to work fine. I will keep an eye on it because it is a critical component of the site and absolutely required.

Turns out you were right but I don’t quite understand what is going on. Let me try to explain. If I put in myothersite.com/About_Us, where About_Us is defined specifically in the mysite.com htaccess file to redirect to an about page, it redirects to an about page.

If I add a line to the mysite.com htaccess file that starts with a match sequence it works fine if I put in mysite.com/whatever but if I put in myothersite.com/whatever it gives me a 404 page.

So to summarize, if I put in a specific name that exists in htaccess, it all works fine but if I try it with a match sequence it only works for mysite.com. The added line in mysite.com htaccess is


RewriteRule ^[a-zA-Z0-9\\&\\_\\-]+/?$ /contactus/index.php [L,QSA]

So then I tried it with mod-rewrite in the myothersite.com htaccess file using your info from before and using


RewriteCond %{HTTP_HOST} myothersite\\.com$ [NC]
RewriteRule .? http://mysite.com%{REQUEST_URI} [L,R=301]

it redirects fine if I just put in myothersite.com but if I put in myothersite.com/whatever it gives me the same error. And to be clear, it still works fine if I put in mysite.com/whatever, it redirects to the contact page. Also tried myothersite.com/About_Us which is defined in the mysite.com htaccess file to redirect to an about us page and it works just fine.

Does any of that make sense?

Disregard the entire previous message. I had a mixup in some directories. :slight_smile: sorry

Okay, after a day and a half here is what works. Again, the purpose of this is to be able to have a secondary site (myothersite) where I can tag on a name (myothersite/myname) and have it redirect to a primary site where I can resolve the name and act on it.

In the htaccess file of myothersite


Redirect 301 / http://mysite.com/

In the htaccess file of mysite (make sure this goes at the end of the file so all the intended redirects match up first, such as mysite.com/About_Us)


RewriteRule ^/?([a-zA-Z0-9\\_\\-]+)/?$ /mydir/index.php?name=$1 [L]

This will pass the $_GET variable “name” to the mydir directory index file without leading or trailing slashes “/”.

Seems so simple once you know how to do it. :slight_smile: