homepage Welcome to WebmasterWorld Guest from 54.211.138.180
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
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...
wolfespawn




msg:1509440
 6:37 pm on Sep 13, 2002 (gmt 0)

Hi,

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 '/'?

THANKS ALOT!

 

jdMorgan




msg:1509441
 7:21 pm on Sep 13, 2002 (gmt 0)

wolfespawn,

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.

Jim

wolfespawn




msg:1509442
 7:44 pm on Sep 13, 2002 (gmt 0)

Jim,

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved