Redirect Syntax

I am using

Redirect 301 /

What I want to do is redirect to and also several other names such as or to

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 .?{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} myothersite\\.com$ [NC]
RewriteCond .?{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

AddHandler php5-script .php

Options +FollowSymLinks -Indexes -MultiViews

RewriteEngine On

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

It does redirect it to 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 .?{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 .?{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

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

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

Did that and switched back to

Redirect 301 /

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][/noparse] they will be redirected to [noparse][/noparse] and not to [noparse][/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 it redirects to

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 If you put anything after that like 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, where About_Us is defined specifically in the htaccess file to redirect to an about page, it redirects to an about page.

If I add a line to the htaccess file that starts with a match sequence it works fine if I put in but if I put in 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 The added line in htaccess is

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

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

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

it redirects fine if I just put in but if I put in it gives me the same error. And to be clear, it still works fine if I put in, it redirects to the contact page. Also tried which is defined in the 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 /

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

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: