Why???

Discuss practical ways rearrange URLs using mod_rewrite.

Why???

Postby patch2112 » Sun May 04, 2008 8:59 am

Hello all,

I've often used...

Code: Select all
RewriteRule ^(.*)\.html$ index.php?page=$1


... in .htaccess, then PHP to grab the page name...

Code: Select all
$page = $_GET['page']


So a URL of www.domain.com/test.html outputs the $_GET['page'] variable as "test". Now, I have a site that all the existings pages have .php extension, but I want to do the same thing. When I do this in htaccess...

Code: Select all
RewriteRule ^(.*)\.php$ index.php?page=$1


And an URL like www.domain.com/test.php, my PHP script outputs "index" as the $_GET['page'] variable.

I've tried lots of things, but can't crack it. Any help PLEASE???

Thanks a million!
Philip
patch2112
 
Posts: 4
Joined: Tue Nov 27, 2007 3:20 pm

Ahhhh

Postby patch2112 » Sun May 04, 2008 9:10 am

Sometimes, you fight things for hours, then find the answer seconds after posting for help ;)

Solution for later generations is that the request gets processed twice through, so add a condition to stop if already has index.php in it...
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/index\.php$ [NC]
RewriteRule ^(.+)\.php$ /index.php?page=$1 [QSA,L]


Thanks anyway!
Philip
patch2112
 
Posts: 4
Joined: Tue Nov 27, 2007 3:20 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 123 guests

cron