Search code examples
apache.htaccesscodeignitermod-rewriteurl-rewriting

How to redirect URL into a new URL using .htaccess?


I want to redirect pages using .htaccess. I am using code igntiter When user type this URL in addresss bar :

form.bixy.com/salesapp

and they hit enter button, the URL should changed into:

form.bixy.com/salesapp/administrator/addusr

I have this .htaccess inside the salesapp folder

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond $1 !^(index\.php|images|stylesheets|system/application/sources/) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/  

</IfModule>

If the line RewriteRule ^(.*)$ index.php?/ is removed, I got The requested URL was not found on this server.

I have little knowledge about .htaccess. Any help is greatly appreciated, thanks in advance.

Edit:

This is my current .htaccess that I put inside salesapp folder:

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond $1 !^(index\.php|images|stylesheets|system/application/sources/)

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)/?$ index.php  [L]

RewriteRule ^/? /salesapp/administrator/addusr[NC,R=301,L]

</IfModule>

It still give me error, but the URL should've worked

The page isn’t redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.


Solution

  • Inside salesapp you can try this .htaccess:

    RewriteEngine on
    RewriteBase /salesapp/
    
    RewriteRule ^(?:administrator)?/?$ administrator/addusr [R=301,L,NC]
    
    RewriteCond $1 !^(index\.php|images|stylesheets|system/application/sources/) [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/?$ index.php  [L]