Forum Moderators: phranque
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]
RewriteRule ^page(.*)$ index.php?page=$1 [L,QSA]
This ^(.*)$ index.php is routing all requests correctly to index.php
But I also need to rename page=1 to page1. Therefore I added a 2nd rule that is ^page(.*)$ index.php?page=$1
Anyone know why the 2nd rule does not work?
thx
[edited by: Kahless at 2:03 am (utc) on July 1, 2009]
Be sure you completely understand the code you already have before you try to modify it! See the mod_rewrite documentation at apache.org.
That said, have you tried putting your last rule ahead of all of the first rule's lines?
Jim
RewriteCond %{REQUEST_FILENAME} !-d
rewrite only if the requested file is not a directory
So based on these 2 conditions and with the order reversed I should be able to access the files that exist. Therefore this leads me to believe the problem is with the rewrite rules. Either one of these 2 below alone work great. It breaks (cannot access real files that exist) when both are added at the same time.
RewriteRule ^page(.*)$ index.php?page=$1 [L,QSA]
RewriteRule ^(.*)$ index.php [L,QSA]
[edited by: Kahless at 12:40 pm (utc) on July 1, 2009]
Made correction to 3rd line. Hopefully this clarifies the problem. This current corrected set above for some reason still does not allow file access. It is as if the first Rewritecond is ignored. If I remove the 3rd rule everything works fine.
[edited by: Kahless at 1:16 pm (utc) on July 1, 2009]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page(.*)$ index.php?page=$1 [QSA,L]
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
Jim
It is working now for root URLs but page numbering is ignored for subdirectories. I therefore made the following change to correct it.
Old
RewriteRule ^page(.*)$ index.php?page=$1 [QSA,L]
New
RewriteRule ^(.*)page(.*)$ $1index.php?page=$2 [QSA,L]
I cannot believe how much time I spent on this. Thanks a million.
Newer:
RewriteRule ^(([^/]+/)*)page(.*)$ $1index.php?page=$3 [QSA,L]
Jim