Welcome to WebmasterWorld Guest from 54.144.243.34

Forum Moderators: Ocean10000 & incrediBILL & phranque

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

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

10+ Year Member



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!

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

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



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

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

10+ Year Member



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

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month