Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite trouble

type in domain.com/page/ goes to domain.com/?p=page

         

mexicoshanty

7:21 am on May 24, 2005 (gmt 0)

10+ Year Member



Hey

Sorry for the vague title but i couldn't thing of anything more specific. I've done was too much googling and haven't found a solution.

here's what i have so far:

RewriteCond %{REQUEST_URI}!^/images/
RewriteRule ^(.*)/$ /?p=$1 [L]

and this works as i hoped for

eg type in domain.com/page/ goes to domain.com/?p=page
but if someone types in domain.com/page they get a page not found error. If it was a real subfolder they'd get redirected to domain.com/page/. I'd prefer to redirect the users to domain.com/page/ rather than rewriting the url (domain.com/page) to domain.com/?p=page

Does anyone have a solution to my problem

Thanks

jdMorgan

2:36 pm on May 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mexicoshanty,

Welcome to WebmasterWorld!

You can add code to explicitly test for a trailing slash on any path that does not contain a filetype -- as indicated by the presence of a "." in the URL-path:


# If path does not end in "/"
RewriteCond $1!/$
# and does not contain a "."
RewriteCond $1!\.
# then add trailing slash and redirect
RewriteRule (.*) http://www.example.com/$1/ [R=301,L]

Jim

mexicoshanty

5:37 am on May 25, 2005 (gmt 0)

10+ Year Member



Thanks jdMorgan!

I got it to work after a bit of tweeking, for some reason the code you provided didn't work.

This is the code i used:

# If path does not end in "/"
RewriteCond %{REQUEST_URI}!/$
# and does not contain a "."
RewriteCond %{REQUEST_URI}!\.
# then add trailing slash and redirect
RewriteRule ^(.*) /$1/ [R=301,L]

Is this ok, or is it flawed somewhere?

BTW nice site here, large active community, don't know how i missed it for so long.