4

i have tried lots of for url rewrite rules in htaccess but i am stuck now. i have to change this url

products.php?id=31

to

products/31 

i have used

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

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

  ## hide .php extension snippet

  # To externally redirect /dir/foo.php to /dir/foo
  RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\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:

products?id=31

But this isn't working. Any ideas?

3 Answers 3

2

Have your complete .htaccess like this:

  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]
Sign up to request clarification or add additional context in comments.

10 Comments

i get this products?id=31 but i need products/31
For css/js just use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with http:// or a slash /.
if i have to do with .htaccess because in website lots of pages available so
Ok try this rule: RewriteRule ^products/(.+?\.(?:jpe?g|gif|bmp|png|tiff|css|js))$ /$1 [L,R=301,NC]
hello sir i really thanks for you, now i have www.aaaa.com/products/some_product_name i want to replace product with tiles.. than what i have to do ??
|
0

you need to use it like that

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

1 Comment

can i see how you did it please
0

use below htaccess rule

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.