D
D
Dmitry Yakovlev2015-06-02 14:48:53
CodeIgniter
Dmitry Yakovlev, 2015-06-02 14:48:53

How to remove controller name from url using htaccess?

I have a site on codeigniter. I need to remove the controller name from the url of the main page only,
i.e. do a 301 Redirect c http://site.ru/controller_nameto http://site.ru
Here is my htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT ,L]
RewriteRule ^controller_name$ http://site.ru/ [R=301,L]
These rules don't work at all.
If you do this, then the controller_name is removed from all urls, and I only need a redirect to the main page
#Redirect 301 /controller_name/ /

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
braun2002, 2015-06-02
@braun2002

Didn't understand the problem. If you need a redirect from the controller to the main page, isn't it easier to write it in the default action?

I
Igor Buksha, 2016-06-04
@ripdamage

I don't know if the question is still relevant, but here's the solution:
1. Don't touch anything in htaccess.
2. Go to application/config/routes.php
3. To replace the www.site.ru/main/hello links with www.site.ru/hello add the line
$route['(:any)'] = " main/$1"; where main is the name of the controller we want to hide.
4. Old links in the menu (or where they are located) in the form of www.site.ru/main/hello
to be replaced with www.site.ru/hello.
5. Everything is ready! Now the main controller will not be displayed in the url.
Good luck!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question