homepage Welcome to WebmasterWorld Guest from 54.196.18.51
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Help with mod_rewrite please
A naive question from a not so bright guy
fmonk




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

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!
:)

 

jdMorgan




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

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

fmonk




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

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.

jdMorgan




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

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

fmonk




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

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.

jdMorgan




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved