Rewrite rule conflicts with directory structure

Oh, the strange things mod_rewrite does!

Rewrite rule conflicts with directory structure

Postby longears » Wed Jan 23, 2008 11:08 am

this url:

test.com/gallery/

rewrites the address bar to:

test.com/gallery/?page=gallery

Here's my rule:

Code: Select all
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]


It does this because I have a directory named 'gallery' in my public_html. It does this for every url that has a matching directory in the public_html directory.

How can I change my rule?

Thanks!!!!
longears
 
Posts: 12
Joined: Fri Jul 27, 2007 1:39 pm

Postby richardk » Wed Jan 23, 2008 11:21 am

To do what, ignore the directories or not redirect?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby longears » Wed Jan 23, 2008 11:24 am

To do what, ignore the directories or not redirect?


I just don't want the address bar to change. I want the address bar to remain 'test.com/gallery/'
longears
 
Posts: 12
Joined: Fri Jul 27, 2007 1:39 pm

Postby richardk » Wed Jan 23, 2008 12:19 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Force missing trailing slashes.
RewriteCond %{SCRIPT_FILENAME}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?page=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby longears » Wed Jan 23, 2008 1:12 pm

Once again, Richard, you're awesome.

I ended up only using the first part of your rule:

# Force missing trailing slashes.
RewriteCond %{SCRIPT_FILENAME}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

If I used this:
Code: Select all
RewriteCond %{SCRIPT_FILENAME} !-d

it broke my rule, and I was already checking to see if it wasn't an actual file (a trick you taught me from an earlier post).

Again, thanks for the help!!
longears
 
Posts: 12
Joined: Fri Jul 27, 2007 1:39 pm

Postby richardk » Thu Jan 24, 2008 11:53 am

If I used this:
Code: Select all
RewriteCond %{SCRIPT_FILENAME} !-d

it broke my rule

Doh.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 11 guests

cron