2

I got a website that using osCommerce which all the page can be access directly with http://www.example.com/pagename.php, but now I would like to tweak the htaccess file so that it can supports http://www.example.com/username and then redirecting to http://www.example.com/account.php?id=username, while other pages still can be access using the same old way.

It means that if the htaccess detect that the URL didn't have any extension, then it will be redirecting to http://www.example.com/account.php?id=username.

Thank you!

Ping
  • 339
  • 7
  • 18
  • 1
    [Seach Engine Friendly URL](http://addons.oscommerce.com/info/2796) ? [Ultimate SEO URLs](http://addons.oscommerce.com/info/2823) ? [SEO, Meta Tags, SEF Urls and osCommerce](http://forums.oscommerce.com/topic/254741-seo-meta-tags-sef-urls-and-oscommerce/) ? – Prix Sep 17 '13 at 03:09
  • Sorry I doesn't want to rewrite my entire site. Thanks for your reply anyway. – Ping Sep 17 '13 at 04:32

2 Answers2

6

You just need one rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/?$ /account.php?id=$1 [L,QSA]
anubhava
  • 761,203
  • 64
  • 569
  • 643
3

You can use this code to remove php extension from URL:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension snippet

# This will redirect you from http://www.example.com/username.php to 
# http://www.example.com/username externally                                                          
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]

# This will redirect you from http://www.example.com/username to 
# http://www.example.com/username internally   
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
Vikas Arora
  • 1,666
  • 2
  • 17
  • 38
  • 1
    This will be rewriting the entire site already right? I want to remain the .php for all the pages, just add one more rewrite so that if there is no extension in the URL it will rewrite automatically. – Ping Sep 17 '13 at 04:35