简体   繁体   中英

htaccess seo url friendly with \ and /

I have search of tires in my web, and I have 3 parameters to search: width, slice, and koter(radius)

I want the to direct after the search to this url: example.com/tires/width/sliceR/koter - > example.com/tires/205/55R/16

the values that I get from the user are only numbers, like: width: 205 slice: 55 koter(radius): 16

And I writing this code:

RewriteRule ^tires/$ /tires.php [L]
RewriteRule ^tires/([0-9/]+)/([^/]+)/([0-9/]+)$ /tires.php?width=$1&slice=$2&koter=$3 [L]


RewriteCond %{QUERY_STRING} ^width=(\w+)&slice=(\w+)&koter=(\w*)$
RewriteRule ^ http://example/tires/%1\/%2\/%3? [R,L]

but it's didn't work... and I have problem with the / in the last url: http://example.com/tires/15/15R/15/ - is work http://example.com/tires/15/15R/15 - isn't work

and also, I have problem with double number: example.com/tires.php?width=205&slice=55&koter=17.5 didn't redirect to url friendly.

thank you and sorry for my ignorance

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+tires\.php\?width=([^\s&]+)&slice=([^\s&]+)&koter=([^\s&]+) [NC]
RewriteRule ^ tires/%1/%2/%3? [R=302,L,NE]

RewriteRule ^tires/$ tires.php [L]
RewriteRule ^tires/([0-9.]+)/([^/]+)/([0-9.]+)/?$ tires.php?width=$1&slice=$2&koter=$3 [L,QSA]

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