homepage Welcome to WebmasterWorld Guest from
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

Newbie to mod_rewrite... how can I do this? example included...

10+ Year Member

Msg#: 27 posted 6:37 pm on Sep 13, 2002 (gmt 0)


This is my first time using mod_rewrite.

I want everything after my root / (slash) to redirect to another page AS LONG as it doesnt contain a '.' (dot) OR another '/' (slash)

Basically, I want 'mysite.com/travis' to redirect to this page, but I do not want

'mysite.com/travis.anything' NOR 'mysite.com/travis/anything' to redirect.

I currently have

RewriteEngine on
RewriteBase /
RewriteRule ^[^.//]*$ /path/toMyRedirect.jsp?oldUrl=%REQUEST_URI} [R]

Except this is now redirecting my INDEX page to it.

When I type in 'mysite.com' it is redirecting... I dont know why .

Could someone please tell me what I need to to, the proper way?

Also, the pages that ARE redirecting properly are sending the parameter '/travis' . Is there a way that i can get it to JUST pass 'travis'
without the leading '/'?




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

Msg#: 27 posted 7:21 pm on Sep 13, 2002 (gmt 0)


You will need to "escape" the special characters, such as "." by preceding them with a backslash "\".

The reason your index page is redirecting is that your server will automatically append a "/" if your visitor attempts to "access www.mysite.com" - It will end up with "www.mysite.com/" and thus satisfy your pattern for redirection.

You might want to break this problem down into two steps initially, and use RewriteCond to prevent redirection of any reference to index.html. i.e. preced your RewriteRule with:

RewriteCond %{REQUEST_URI} !^(www\.)?mysite\.com/(index\.html)?$

This should (assuming I typed it correctly) stop requests for www.mysite.com, mysite.com, www.mysite.com/, mysite.com/, www.mysite.com/index.html, and mysite.com/index.html from being redirected.

Gotta go for now (meeting) - try escaping the special chars, adding the above RewriteCond, and see what happens.



10+ Year Member

Msg#: 27 posted 7:44 pm on Sep 13, 2002 (gmt 0)


Thanks very much for your reply. I am going to try the condition you suggested. Question on that though.. Is there an environment variable that I can use (like HOST ) or something that I can plug into that regular expression so it is dynamic for any server/virtual host I put it on?


I will let you know if I get the first half working.. thanks a ton :)

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