0

I am trying to write SEO friendly clean URLs, using Apache Mod-Rewrite.

My existing URLs look like this:

index.php?p=my-page 
index.php?p=my-page&id=3 
index.php?p=my-page&cat=5
index.php?p=my-page&month=201606

I have tried it and this is my code sofar in .htaccess:

RewriteRule ^([\w-]+)/?$ index.php?p=$1 [L,QSA,NC]
RewriteRule ^([\w-]+)/([0-9]+)/?$ index.php?p=$1&id=$2  [L,QSA,NC]
RewriteRule ^([\w-]+)/([0-9]+)/?$ index.php?p=$1&cat=$3 [L,QSA,NC]
RewriteRule ^([\w-]+)/([0-9]+)/?$ index.php?p=$1&mth=$4 [L,QSA,NC]

But, My problem is, when it change 2nd variable name in query string, its always identifying as id not cat or mnt.

Can anybody tell me how fix this issue?

Thank you.

user3733831
  • 2,886
  • 9
  • 36
  • 68
  • 1
    You cannot have 3 different rules for same pattern: `^([\w-]+)/([0-9]+)/?$` only first of these 3 will execute all the time. – anubhava Aug 24 '16 at 15:02
  • @anubhava, Thank you for your comment. Then what would be the solution for this? – user3733831 Aug 24 '16 at 15:03
  • You will need to differentiate 3 URLs some other way. May be by using some prefix like `cat/my-page/5`, `month/my-page/123456` etc – anubhava Aug 24 '16 at 15:07
  • @anubhava, I couldn't get what you have mentioned. Can you kindly elaborate it? Thank you. – user3733831 Aug 24 '16 at 15:11
  • What are the "user friendly" URLs for these 3 "ugly" URLs. (Note that these are "user friendly", not "SEO friendly" URLs. The SE's don't really care.) – MrWhite Aug 24 '16 at 15:43
  • @user3733831: [Read this helpful answer](http://stackoverflow.com/a/31280108/548225) as it is impossible to write this much in comments – anubhava Aug 24 '16 at 15:57

0 Answers0