RewriteRule in htaccess problem

Hi everyone, I really hope someone can help me?

I'm trying to get my urls to look like this:

...when the actual file is an html file to be 'include'd in a index.php for example: index.php file would look something like this:
... blah blah ...
  if (file_exists($HTTP_GET_VARS[p].".htm")) {
    $page = $HTTP_GET_VARS[p];
    echo "The file filename exists";
  } else {
    $page = 'products';
    echo "The file filename does not exist";
... blah blah ...

...i've tried this in my htaccess file:

RewriteEngine On
Options +FollowSymlinks
RewriteRule ^products/(.*) /products/index.php?p=$1

Please can someone help me as this is becoming a huge headache!
This is probably fairly easy to someone who knows apache rewrite stuff.

Thank you,

Rob Holmes
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

your problem is probably that, when you redirect someone to /products/index.php?p=whatever, that redirect is picked up by the RewriteRule *again* and converted to /products/index.php?p=index.php?p=whatever etc etc.

Add the 'Last' flag to the rule and it should work:

RewriteRule ^products/(.*) /products/index.php?p=$1 [L]

robholmes83Author Commented:
Thank you _Blue that really sounded like the answer... so i tried it but still getting page not found. It doesnt even goto the index.php page.

Any ideas?

Rob Holmes
I think it's a problem in what's happening before your rewrite rule gets implemented.
Many apache servers are designed to interpret ""
as ""
they automatically add a trailing / and interpret an extensionless value as a directory

try adding a 404 rule to your htaccess
then have the php file it goes to  echo $_SERVER['REQUEST_URI']
if that does it, then you can't just use the rewriterule, instead set up an "error" document

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

make sure mod-rewrite is installed!!


all the way down with "modules" there must be: "mod_rewrite"

put in the httpd.conf:

<Directory /www/htdocs/yourdomain>
AllowOverride All


RewriteEngine On
RewriteRule ^php/tutorials/(.*)/(.*)/(.*)/products/index.php?p=$1&var2=$2&var3=$3
RewriteRule ^php/tutorials/(.*)/(.*)/(.*)products/index.php?p=$1&var2=$2&var3=$3
RewriteRule ^php/tutorials/(.*)/(.*)/products/index.php?p=$1&var2=$2
RewriteRule ^php/tutorials/(.*)/(.*)products/index.php?p=$1&var2=$2
RewriteRule ^php/tutorials/(.*)/products/index.php?p=$1
RewriteRule ^php/tutorials/(.*)products/index.php?p=$1
robholmes83Author Commented:
Hi php-webdesign,

I've had a look at phpinfo() and there is no mod_rewrite installed.

I have no access to the server and i dont think the hosting company will implement it for me.

Do i have any other options but to just make the url's like this:



Rob Holmes
no, when mod rewrite is not installed you cannot change the way you call on your page... sorry
(at least not that i know off)

But you can always ask them to install mod-rewrite (or find another hoster ;))
Yes, you can, with just a little adjustment to your site.

See for a detailed guide


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nice :) didn't know that!
php-webdesign... that's only mostly true
if you add an error document rule to htaccess, you can get the same sort of control (albiet not as efficiently):

e.g. I use this to protect some of the pages on my server (in particular to protect jpeg files):


Order Allow,Deny
Deny from all

# To allow execution of cgi scripts in this directory uncomment next two lines
#AddHandler cgi-script .bat .exe .pl .cgi
Options -Indexes

ErrorDocument 403 /finder.php

<FilesMatch "\.(gif|png|pdf|jpg|jpeg|swf)$">
Allow from all


since every attempt to access any  *.php   will come up as forbidden

they will always load the file finder.php:

        $file = $_SERVER["DOCUMENT_ROOT"] . $_SERVER["REQUEST_URI"];
        if (file_exists($file))
            include "error.php";



And there you go.  Now you just have to translate the REQUEST_URI to the path and load the appropriate fil.e
robholmes83Author Commented:
Thank you everyone who was involved with this problem!

I have decided to split the points as there wasn't really a complete solution, but the three guys eeBlueShadow, php-WebDesign and virmajor shared the points as they made major contributions to me making my decision as to what action to take next.

I decided to give eeBlueShadow the accepted answer as the link he has given has really helped me for the future.

Thanks guys!

Rob Holmes

PS speak to you soon because no doubt i'll be back soon.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.