Sometimes, we want to create friendly URL in PHP.
In this article, we’ll look at how to create friendly URL in PHP.
How to create friendly URL in PHP?
To create friendly URL in PHP, we can add code to .htaccess to rewrite URLs.
For instance, in .htaccess, we write
RewriteEngine on
RewriteRule ^/news/([0-9]+)\.html /news.php?news_id=$1
to redirect /news.php?news_id to /news with the news_id
value after it and .html
after that.
Then this maps
/news.php?news_id=100
to
/news/100.html
Conclusion
To create friendly URL in PHP, we can add code to .htaccess to rewrite URLs.