SEO friendly URLs

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

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,

Thanks for your help. I am running a Cloud Server with Rackspace and I have added the code to my virtualhost setting in /etc/conf/httpd which now looks as follows:



  # Admin email, Server Name (domain name) and any aliases
  ServerAdmin admin@mydomain.com
  ServerName  demo.mydomain.com
  ServerAlias demo.mydomain.com
 
  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.php
  DocumentRoot /home/demo/public_html

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

However, this is not working... I still receive a 404 error message. Any ideas what else I could try?

This URL works: http://demo.mydomain.com/category.php/1/
This URL does not work: http://demo.mydomain.com/category/1/

Thanks,

Greg

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