I am trying to implement URL rewriting in my PHP application. Can someone share a step by step procedure of implementing URL rewriting in .htaccess.
In my application I want to implement following URL
www.domain.com/shop/shop.php?shopname=myshop&sh=1
to
www.domain.com/shop/myshop
i use the follwing
RewriteEngine On
RewriteBase /shop/
RewriteCond %{THE_REQUEST} /shop\.php\?shopname=([^\s&]+)&sh=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ shop.php?shopname=$1&sh=$2 [L,QSA,NC]*
It shows the url like www.domain.com/shop/myshop
But not pointing to www.domain.com/shop/shop.php?shopname=myshop&sh=1
If I understand you correctly, you can do what you want with:
RewriteCond %{QUERY_STRING} ^id=([^&]*)&name=(.*)$
RewriteRule ^/shop/shop.php$ /shop/$2?id=$1
The RewriteCond check for a query string of the correct format and extracts the values. $1 = the ID and $2 = the name.
The RewriteRule rewrites a URL of the correct format to the new format, inserting the name and id parameters from the RewriteCond.
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.