Search code examples
.htaccesscodeigniterurl-rewritingcodeigniter-urlcodeigniter-routing

Custom URL rewriting not working in codeigniter


I use the code below in a Codeigniter htaccess file

RewriteRule ^([^.]+)-vacation$ /search?location=$1

When i access it with the url www.example.com/moscow-vacation, it gives me a 404 error.

I have used the above htaccess code in a core php application. It works fine there.


Solution

  • Most likely, you don't have a search script. If the script is named search.php, you can use this slightly modified rule

    RewriteRule ^([^.]+)-vacation$ /search.php?location=$1
    

    If you have a controller named Search with a method location, you can either rewrite directly to

    RewriteRule ^([^.]+)-vacation$ index.php/search/location/$1
    

    or try

    RewriteRule ^([^.]+)-vacation$ search/location/$1