jumax
jumax

Reputation: 1577

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/

Upvotes: 0

Views: 62

Answers (1)

mario
mario

Reputation: 145482

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.

Upvotes: 1

Related Questions