简体   繁体   中英

url rewriting and pass the form's values

I'm having e commerce website in php. And now moving to fancy urls, url rewriting.

for that i've variable length of parameters with optional variables too.

for example,

http://example.com/product.php?page=e&id=23&color=blue&size=xxl&width=200&height=100

Here, the parameters are optional That means, some variables may or may not participage in the url except id .

here, page=e is fixed and it is not dynamic. ( the reason behind is i've other rewritten rules like ^categories , ^toys etc..

and re-written url should be one of these,

http://example.com/e/23/color-blue/size-xxl/
http://example.com/e/26/color-black/width-500/height-900/
http://example.com/e/56/type-shirt/color-white/height-345/size-xl/

i've tried below with no luck,

RewriteRule ^e/([^/.]+)/?$ product.php?page=e&url=$1  [L,NC,QSA]

i'm getting all $_GET values like this,

http://example.com/product.php?page=e&id=23&color=blue&size=xxl&width=200&height=100

but i'm trying to achieve like this,

http://example.com/e/23/color-blue/size-xxl/width-200/height-100

how can i pass the queries with slashes and not & 's.

that main idea behind above last url is to process the whole fancy url into simple one in php,

and then use those variables in the page script. is there any better solution than this ??

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

RewriteEngine On
RewriteBase /

RewriteRule ^(e)/([0-9]+)/([^-]+)-([^/]*)(/.*)?$ product.php$5?page=$1&id=$2&$3=$4 [L,QSA]

RewriteRule ^(product\.php)/([^-]+)-([^/]*)(/.*)?$ $1$4?$2=$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