954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

remove ".php" from URLs wth .htaccess file

Hello,

I would like to ask the way to change http://abc.com.hk/article.php?product=1&side=2 to http://abc.com.hk/article/1/2

I just write in .htaccess as below:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

It works only for this link: http://abc.com.hk/article , but not valid for http://abc.com.hk/article/1/2

porkchop970
Newbie Poster
1 post since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

That's because you need to do something else (I'm pretty sure)..

For example, the code that you have WILL remove .php from the url's ( www.abc.com/article.php -> /article) but, because you are requesting variables (using $_GET) you need to provide something else.

The .htaccess works by taking the url: /article/1/2 and just redirects it to: /article?id=1&page_no=2.. for example..

Let me give you an example: http://net.tutsplus.com/tutorials/other/using-htaccess-files-for-pretty-urls/

Hope this helps you =)

phorce
Posting Whiz
362 posts since Jul 2011
Reputation Points: 31
Solved Threads: 26
 

try this, name this .htaccess and put it to root

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /

RewriteRule ^article/(.+)/([0-9]+)$ article.php?product=$1&side=$2


btw this code only works for that certain pattern article.php/watever/watever, because im also a newbie on htaccess im just still reading right now on the basic parts, maybe the conditional statements in htaccess RewriteCond can do the trick, but i haven't read that part yet :D

vaultdweller123
Posting Pro
554 posts since Sep 2009
Reputation Points: 42
Solved Threads: 75
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: