We help IT Professionals succeed at work.

rewrite rule quick question

jbrashear72
jbrashear72 asked
on
Medium Priority
259 Views
Last Modified: 2010-03-04
I am trying to write a rewrite rule to go into .htaccess

I want to show a url like this:
http://www.domain.com/article/

but article is really article.php

how does this re write rule need to be written.
Comment
Watch Question

Author

Commented:
I tried the attached code below.
it works when I go to:

/article.php
and works with
/article

and works with
/article?test=1

but I need it to work with
/article/test/1

I am using the  $PATH_INFO to break out the URL.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ $1.php
 
 
 
**********************************************************
 
$var_array = explode("/",$PATH_INFO);
would give:
 
$var_array[0] = "article.php"
 
$var_array[1] = test
 
$var_array[2] = 1

Open in new window

Top Expert 2008
Commented:
> but I need it to work with
/article/test/1

so you don't need to match /article only?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^./]+)/ $1.php

Open in new window

Explore More ContentExplore courses, solutions, and other research materials related to this topic.