I want to rewrite URL using .htaccess in codeigniter but it's not working. Can you please figure it out. Want to change URL from:
www.site.com/mauritius_holiday_rentals/apartment/anyname
to
www.site.com/mauritius_holiday_rentals/anyname
My current .htaccess file contains:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteRule ^mauritius_holiday_rentals/([A-Za-z0-9-]+)/?$ mauritius_holiday_rentals/apartment/$1 [L,QSA]
First four line is for removing index.php from URL which is working fine.
If routes file is set to access new url and you want to set redirection for old URLs then Use following code in .htaccess. otherwise let me know in detail what you want to do.
RewriteEngine on
RewriteBase /
RewriteRule /mauritius_holiday_rentals/apartment/$1 /mauritius_holiday_rentals/$1 [R=301,L]
Routes.php config file code
$route['mauritius_holiday_rentals/(:any)']="mauritius_holiday_rentals/apartment/$1";
Let me know if any problem.
RewriteEngine On
RewriteBase /yourProjectName/
RewriteCond $1 !^(images|stylesheets|javascript)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yourProjectName/index.php?/$1 [L]
Try to use codeigniter routing system
https://www.codeigniter.com/user_guide/general/routing.html
Related
I am working in a site which has been developed in codeigniter,
To remove index.php from url I wrote rewrite rule in htaccess, now , there is anotheher need to be arise, that is I need to replace http:// to www in url,for that I wrote the code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^vrinfosystem.com$
RewriteRule (.*) http://www.vrinfosystem.com/$1 [R=301,L]
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
but I got issues, the stylesheet and js are no found.
I changed the base url too but it didn't help.
if I wrote following line above the HTTP_HOST
RewriteRule ^(.*)$ index.php?/$1 [L]
the it will work fine but the index.php will retain in url.
Ho can I solve this issue?
are u sure u have changed your config?
if you don't go to application>config>config.php than scroll down till you find this
$config[‘index_page’] = 'index.php';
change it too
$config[‘index_page’] = '';
There are a group of different scripts for this. This is the only one that worked for me across several sites
RewriteEngine on
RewriteCond $1 !^(index\.php| (.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
I am new in codeigniter and i am trying to remove index.php from URL in Codeigniter but not able to do this.
I wrote code in my .htaccess file-
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
My Apache mod_rewrite is enable.
But still got 404 error when i am trying to access any controller without using index.php.
Please help.
Thanks.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
</IfModule>
Is the code I'm using, it works on every hosting platform I've used it on.
This should help you,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
check this code of htaccess file.
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|images|css|js|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
you can find your answer refference here
My .htaccess file is not working
moreover can you share your base url with us? as this error may be due to wrong baseurl set.
I am trying to rewrite the following URL via .htaccess:
http://website.com/dealer_home.php?id=dealer1
The result I am aiming for is this, where dealer1 is the username which is set as variable:
http://website.com/dealer1
I have tried this rule in .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)$ /dealer_home.php?id=$1 [L]
However I get "Internal Server Error" message when trying to load any of the website pages.
Can you provide some advice where I am doing wrong?
EDIT:
I tried also RewriteRule ^(.*)$ dealer_home.php?id=$1 [PT] but no success.
Thank you!
Maybe it's a conflict with existing files/folders and root uri.
Try this code instead
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /dealer_home.php?id=$1 [L]
This rule will match every url like domain.com/something if something is not an existing file or folder.
So if you have other rules then you should put them above this one.
EDIT: to avoid duplicate content and to redirect old format to new url format
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/dealer_home\.php\?id=([^&\s]+)\s [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /dealer_home.php?id=$1 [L]
I'm working on a project in Codeigniter that doesn't use the standard routing.php file.
It calls the functions like this: test.vi/index.php/controller/function.
My goal is to remove the index.php from the url with a htaccess rewrite:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
And also this config.php change:
$config['index_page'] = '';
My question is do I need to route all the controllers/functions in my route.php or can it be done without using the route.php file?
first make sure you enabled mod_rewrite in httpd.conf:
to do so add/make sure it exsits this line
LoadModule rewrite_module modules/mod_rewrite.so
then create .htaccess in your codeigniter root folder (next to index.php file) not application folder.
.htaccess
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|img|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
codeigniter take care of all routings for you; so for
controlers/welcome.php method=hello u can access it by
http://localhost/welcome/hello
its not like laravel you need to specifically add route; codeigniter automatically Fitch controller for you. unless you have it stored in a different location or inside subfolder then you dont need to touch route.php except for setting your default route.
Here's my redirect in .htaccess for a live codeigniter site. The second part exempts certain directories.
#Redirect non-www to www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond $1 !^(index\.php|phpinfo\.php|test\.php|example\.php|images|i|css|js|beta|captcha|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
THIS works perfect for me... give it a try..
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
try this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /test.v/index.php?/$1 [L]
I guess everyone forget about add test.vi folder name on .htaccess
I want to create an .htaccess rule.
My link looks like below:
http://gpuzzles.com/brain-questions/funny-puzzles-and-riddles
This can be redirected to gpuzzles.com/brain-questions/index.php (and i can get parameters as funny-puzzles-and-riddles)
I tried to create a new RewriteRule, but it's not working:
RewriteRule ^brain-questions/(.+)$ /brain-questions/index.php?var=$1
Try this code in /brain-questions/.htaccess:
RewriteEngine On
RewriteBase /brain-questions/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?var=$1 [L,QSA]