Rick Joe Rick Joe - 4 months ago 12
PHP Question

how to open mypage.com/link-page in htaccess without affect other page?

I have this code to open


RewriteRule ^([a-zA-Z0-9_-]+)$ home.php?id=$1 [L,QSA]

the problem is, if anyone types: mywebsite.com/any-post-name
the page wont open.
So I add:

RewriteRule ^([a-zA-Z0-9_/-]+)$ home.php?id=$1 [L,QSA]

now, every other page goes to home.php too, for example, I have category:
mypage.com/category/name-category -> will come to home.php

RewriteRule ^category/([^(.*)].+)/(\d+)/?$ category.php?categoria=$1&id=$2

how to solve this?


Putting the / in the character class allows it multiple times because of the quantifier (+). If you move that to the end of the regex and make it optional it should work for you.


Demo: https://regex101.com/r/jA0oZ1/3



Demo: https://regex101.com/r/jA0oZ1/4