rewrite anything after root before second slash and...

Discuss practical ways rearrange URLs using mod_rewrite.

rewrite anything after root before second slash and...

Postby Travis » Fri Sep 13, 2002 10:31 am

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!!!!!!!
Travis
 

This will help you

Postby demon321 » Thu Nov 28, 2002 8:53 pm

http://www.fastcgi.com/archives/fastcgi ... 02199.html

I was trying to do the exact same thing with the /blah - rather than /~blah, mine is going to a php page with DB content behind it - my final rules after reading that hyperlink above turned out to be:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/$ /index.htm [N]
RewriteCond /home/httpd/sites/SITE/%{REQUEST_FILENAME} !-d
RewriteCond /home/httpd/sites/SITE/%{REQUEST_FILENAME} !-f
RewriteRule ^/([^/]+) http://tmp.SITE.com/page.php?vpath=$1
</IfModule>

This basically says if the request is / (root) convert it into index.htm (your default page) and then apply the following rules to the request:
1. Check if the filename is a directory (needs the full local path to verify this
2. If it isn't a directory (!-d) check if it is a file name
3. If it isn't a file (!-f) rewrite the url with the request
Mine takes the /blah request and finds the blah in a DB to then display content for a simple user page

Hope this helps
demon321
 


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 48 guests

cron