Home > Blockchain >  How do I rewrite an id to a name via htaccess
How do I rewrite an id to a name via htaccess

Time:09-17

I am trying to rewrite the title ID through htaccess but it does not work. I used several different codes in htaccess but it does not work. When I went to the url by name it did not show me any post, but with ID it works very well.

I am using this code in htaccess:

RewriteRule ^([0-9a-z] )/?$ news-details.php?nid=$1 [NC,L,QSA]

ID for posts/categories:

127.0.0.1/new/news-details.php?nid=89
127.0.0.1/new/category.php?catid=9

CodePudding user response:

Yes it works through the id "/new/89" you mentioned but not with url "/new/89/name-news"

Then change the rule (the regex) to allow /<id>/<slug> (no trailing slash), for example:

RewriteRule ^(\d /[\w-] )$ news-details.php?nid=$1 [NC,L,QSA]

<id>/<slug> is then past as the value of the nid URL parameter.

  • Related