简体   繁体   中英

How to make correct mod_rewrite rules in.htaccess

I am trying to make rewrite rule which rewrite this long url to a SEO friendly one. However, my rule didn't work and the destination url become a 404 page. I would appreciate any helps. Thank you!

This is an example of original URL

http://www.mydomain.com/index.php?module=product&pId=102&id=14495&category=computer/DELL&start=0/

This is my rewrite rule

RewriteRule ^module/([^/] )/pId/([^/] )/id/([^/] )/category/([^/] )/start/([^/]*)$ /index.php?module=$1&pId=$2&id=$3&category=$4&start=$5 [L]

This is transformed URL

http://www.mydomain.com/index/module/product/pId/102/id/14495/category/computer/DELL/start/0/

Just from a quick glance, you are matching for /start/[^/]*$ . But your URL contains a trailing forward slash start/0/ , which your regex excludes.

So it might be best to either allow a spare slash with /? or rather make the last match pattern completely imperceptive with /start/(.*)$ allowing everything.

But anyway, just removing file extensions and trading ampersands and equal signs for forward slashes doesn't make for nicer or user-friendly URLs. The goal should be parameter consolidation for readability. Contemporary search engines don't care about GET parameters really.

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