简体   繁体   中英

Rewrite Url in localhost is not working

I searched for many documentation, question and answers for rewrite url as given below

FROM

http://localhost/rewrite/product.php?id=1

To

http://localhost/rewrite/product.php/1

Than i use this online tool to generate url rules. My Rule Is

Options +FollowSymLinks
RewriteEngine on

RewriteRule /id/(.*) product.php?id=$1

And i also checked httpd.conf . Allooverride is on.

<Directory />
    AllowOverride All
    Require all denied
</Directory>

But Still This Url Is not changing to desire url. where i am going wrong. i dont have much knowledge in Rewrite and mod_rewrite. so please be patient to me.

The following will redirect http://localhost/product/1 to http://localhost/product.php?id=1

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/product/([0-9]+)$ [NC]
RewriteRule ^product/(.*)?$ product.php?id=$1 [L,QSA]

So to setup, create a product.php file in the base of the localhost directory with the following code:

<?php
var_dump($_GET);

And then open http://localhost/product/1 and it should display:

array(1) {
["id"]=>
  string(1) "1"
}

What that rule does is that if you now access for example the URL http://localhost/rewrite/product.php/1 , it will map it to the URL http://localhost/rewrite/product.php?id=1 , and you will have access to the id GET parameter in code.

It will not convert an url from http://localhost/rewrite/product.php?id=1 to http://localhost/rewrite/product.php/1 , you will have to do that yourself in code or with a redirect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM