SEO friendly URLs

5 posts by 2 authors in: Forums > CMS Builder
Last Post: February 4, 2013   (RSS)

Hello,

I have managed to get the SEO friendly URLs working so that question marks are replaced with forward slashes, however I can't seem to get the rewrite rule to remove the ".php" extension. I am using the following in my httpd file under my <VirtualHost> setting:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}.php -f

RewriteRule ^(.+)$ $1.php [L,QSA]

When I remove the ".php" from the file name I receive a 404 error message.

Could someone please give me a hand getting this to work?

Thank you,

Greg

Hi Greg,

I've done some quick local testing, and this htaccess rule worked for me:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

For this to work your Apache server will need to have the rewrite engine enabled, but most hosting companies have this module switched on by default.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi Greg,

I tried both the links below, but neither is working for me. Is this a server that you have set up from scratch? My guess is you might not have mod rewrite enabled/installed. I'm not sure what the next step should be as the defaults installed and linux variant used is different for every hosting company.  I would contact your hosting company about this issue. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi Greg,

Yes, this is a server I setup myself... mod_rewrite is installed because it's working on other websites I am hosting. Maybe it's not enabled for this particular account.

I will contact my hosting company as you suggested and see if they can help.

Thanks for looking into this for me.

Regards,

Greg