Search code examples
php.htaccesscodeignitermod-rewrite

How to rewrite url with htaccess?


I have to build up a bank search website. I want to rewrite url like below link

bank

Please see above link. In this when you select bank and all details the url is also changing.

I want to use same url in codeigniter website which is the replica of this site.

But all of you knows that codeigniter work on mvc so when this type of url comes to my system it says not found. So how can i achieve this with htaccess

here is my htaccess code

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>

Solution

  • The .htaccess route with mod_rewrite

    Add a file called .htaccess in your root folder, and add something like this:

    RewriteEngine on
    RewriteRule ^/?Some-text-goes-here/([0-9]+)$ /picture.php?id=$1
    

    This will tell Apache to enable mod_rewrite for this folder, and if it gets asked a URL matching the regular expression it rewrites it internally to what you want, without the end user seeing it. Easy, but inflexible, so if you need more power:

    for more info check this