Page 1 of 1
Mod Rewrite dilemma
Posted: Mon Aug 31, 2009 3:24 am
by AlanG
Got a mod rewrite problem, hopefully someone can help.
I have a dynamic url I want changed.
Original: index.php?page=home
Target: home
.php
I tried the following code but it returns a 500 error. Any ideas? Thanks for any help.
Code: Select all
RewriteEngine On
RewriteRule ^([^/]*)\.php$ /index.php?page=$1 [L]
Re: Mod Rewrite dilemma
Posted: Mon Aug 31, 2009 3:35 am
by Benjamin
Code: Select all
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)\.php$ index.php?page=$1 [L,QSA]
I believe that should work for you. Otherwise check the server error log. The 500 error could be another issue, but more than likely it was due to permissions.
Re: Mod Rewrite dilemma
Posted: Mon Aug 31, 2009 4:11 am
by AlanG
Works perfectly.

Thank you very much. I'll have a look into the two other arguments you gave.

Thanks again.
Re: Mod Rewrite dilemma
Posted: Mon Aug 31, 2009 4:13 am
by Benjamin
Welcome. The other two conditions specify to only rewrite the request if a file or directory by the same name does not exist. Also note that I removed the / from in front of index.php in the RewriteRule.
Re: Mod Rewrite dilemma
Posted: Wed Sep 02, 2009 5:50 pm
by AlanG
Thanks for the help earlier. I just need another adjustment so it's working perfectly. I want all my pages to show up as .html.
index.php?page=home now shows up as home.html but i also want contact.php to show up as contact.html, just to keep the site consistant. Any thoughts?
Code: Select all
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /~user/index.php?page=$1 [QSA,NC]
RewriteRule ^(.*)\.html$ /~user/$1.php [NC]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
ErrorDocument 404 /~user/index.php?page=page+not+found
Thanks alot for the help.
