简体   繁体   中英

htaccess RewriteRule generate url with 2 parameters in any order

I have this url with 2 parameters

https://mywebsite.com/folder/subfolder/page.php?id=999&title=this-is-a-test

and I need a rule to generate the following url

https://mywebsite.com/page/this-is-a-test-999/

I tried this rule

RewriteEngine On
RewriteRule ^page/([^-]*)-([^-]*)/$ /folder/subfolder/page.php?&id=$1&title=$2 [L]

and I get this url

https://mywebsite.com/page/999-this-is-a-test/

what changes I need to do in the rule to get

this-is-a-test-999

instead of

999-this-is-a-test

any idea how to fix it?

Try this rule ( /page/this-is-a-test-999/ <> /folder/subfolder/page.php?&id=999&title=this-is-a-test )

RewriteEngine On
RewriteRule ^page\/(.*)-(\d+)\/$ /folder/subfolder/page.php?&id=$2&title=$1 [L]

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