Madan Sapkota Madan Sapkota - 7 months ago 7
PHP Question

Apache rewrite query string to CodeIgniter like URL

Here is a sample URL with query string. The

keyword
is anything that User Search in my website or redirect from other websites, search engines etc.


http://example.com/search.php?q=keyword


and the equivalent CodeIgniter URL


http://example.com/search/now/keyword (search = controller and now =
method)


How to Rewrite the URLs in Apache .htaccess to create URLs like CodeIgniter?

Answer
RewriteRule ^/?search/now/(.*)$ /search\.php?q=$1

OR you can hide url query

RewriteRule ^search.php?id=(.*)$ /search.php [L,R=301]