Welcome to WebmasterWorld Guest from 23.22.79.235

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Help with mod_rewrite please

A naive question from a not so bright guy

   
4:13 am on Oct 19, 2002 (gmt 0)

10+ Year Member



I'm trying to redirect
[mysite.com...]
to
[mysite.com...]

I found some examples on how to do the opposite but I couldn't reverse-engineer them to what I want.

Is mod_rewrite what I need, and if so can someone clue me in?

TIA,

Frank.

PS
Arrgh!
:)

4:20 am on Oct 19, 2002 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Sure,

# Redirect www.mysite.com to mysite.com:
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
RewriteRule ^(.*)$ [mysite.com...] [R=permanent,L]

# Redirect anything except mysite.com to mysite.com:
RewriteCond %{HTTP_HOST} !^mysite\.com$
RewriteRule ^(.*)$ [mysite.com...] [R=permanent,L]

<added>The second version is useful if you have multiple TLDs, like .com and .org, pointed to the same site and you want to redirect them all to the same URL, as well as removing the "www."</added>

More details here [httpd.apache.org].

Jim

8:05 pm on Oct 19, 2002 (gmt 0)

10+ Year Member



Thanks, Jim

But

Both examples throw up an Internal Server Error :(

Back to the drawingboard, I'll dig through the Apache link you sent and see if I can make heads-or-tails out of it.

Thanks again.

8:23 pm on Oct 19, 2002 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Frank,

Make sure you've got symbolic links enabled, and that the rewrite engine is enabled. And before even checking that, make sure that the rewrite module is installed and that you have priveleges to use it!

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^mysite\.com$
RewriteRule ^(.*)$ [mysite.com...] [R=permanent,L]

This code has worked for years on my site. If the above hints don't help you, then you may stickymail me your actual code if you think there's some subtle typo in your version - it does have to be letter-perfect.

Jim

9:00 pm on Oct 19, 2002 (gmt 0)

10+ Year Member



Thanks so much for the info!

I'll follow all the advice when I get the time, looks like I may need to get my host's admin on the line.

Frank.

9:36 pm on Oct 19, 2002 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Frank,

Tell them you need "AllowOverride +Options" in the directory level above the directory your .htaccess file is in. If your .htaccess is in your site's top-level directory, then they will need to add this option in the server config for you. Actually, you might want to ask for "AllowOverride All" at first, and see if they'll go for it... :) (See the Apache Core docs for AllowOverride.)

Jim