Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have tried lots of URL rewrite rules in .htaccess but I am stuck now. I have to change this URL:




I have used:

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

    ## don't touch /forum URIs
    RewriteRule ^forums/ - [L,NC]

    RewriteCond %{THE_REQUEST} \s/+products(?:\.php)?\?id=([0-9]+) [NC]
    RewriteRule ^ products/%1? [R,L]

    RewriteRule ^products/([0-9]+)/?$ products.php?id=$1 [L,QSA]

    ## hide .php extension snippet
    # To externally redirect /dir/foo.php to /dir/foo
    RewriteCond %{THE_REQUEST} \s([^.]+)\.php [NC]
    RewriteRule ^ %1 [R,L]

    # To internally forward /dir/foo to /dir/foo.php
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.+?)/?$ $1.php [L]

Using this I get the following result:


But all images and CSS not displaying. Any ideas?

share|improve this question
Are you using relative URLs to your images / CSS files? – w3dk Dec 23 '13 at 10:40
You have lots of rewrite rules that look like they should do the same thing. Figure out which one is the one that is actually working. I suspect you only need the forum rewrite rule and this one: RewriteRule ^products/([0-9]+)/?$ products.php?id=$1 [L,QSA] The duplicate rules should be removed so you can understand what is happening. – Stephen Ostermiller Dec 23 '13 at 10:49

Try this:

RewriteRule ^(.*)\/$ $1.php [NC]
share|improve this answer

about the images and CSS not displaying; If your URL gets rewritten to something like products/31 keep in mind that relative links inside the html are now relative to products/ even though the php script itself sits in the root. Because the html gets interpreted by the browser and the browser thinks you are in the products/ folder. You can use absolute urls (starting with http://hostname/ or just relative to root, thus starting with /) or have them rewritten too.

share|improve this answer

Try this:

RewriteEngine on
RewriteRule ^(.*) $1 [L]
RewriteRule ^products/$ products.php?id=31 [L]

This code working fine for me. For more details: http://www.askapache.com/htaccess/htaccess.html

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.