SEO friendly URLs

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

By gversion - February 3, 2013

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

By gversion - February 4, 2013

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

By gregThomas - February 4, 2013

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

By gversion - February 4, 2013

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