简体   繁体   中英

CodeIgniter : How to remove 'folder name' in CodeIgniter URL

So I have URL Like : http://localhost/folder_name/home

I want to remove/delete 'folder_name' from URL so my URL becomes http://localhost/home .

I already try this code :

RewriteEngine On
RewriteBase /

RewriteRule ^((?!folder_name/).*)$ folder_name/$1 [L,NC,R]

This code let me access the url in http://localhost/home , but everytime after I 'press ENTER' the URL in browser. the URL will become http://localhost/folder_name/home again

is it possible to 'permanently remove' the folder name ?

Thanks :)

Maybe the folder_name still be remembered on your web browser, and then when you hit Enter, it auto-complete the old URL.

I think you should try remove cookies from your web browser and try again. Gook luck!

try using virtual hosting it more flexible you can even set your own url like myapp.dev .

refer to this info:

Windows:

http://en.kioskea.net/faq/8485-configuring-apache-and-windows-to-create-a-virtual-host

in Linux it depends to your Distribution.

Given:

http://localhost/folder_name/home

A. If you're using XAMPP...
1) In your htdocs directory, transfer all the contents of folder_name outside to your htdocs directory.
--> the contents would include: application folder , assets folder , etc.

2) Delete the folder, folder_name .

B. If you're using LAMP...
1) In your /var/www/html/ directory, transfer all the contents of folder_name outside to your /var/www/html/ directory.
--> the contents would include: application folder , assets folder , etc.

2) Delete the folder, folder_name .

A & B
3) In your application/config/config.php file...

$config['base_url'] = 'http://localhost/';

B only
4) do: sudo service apache2 restart

Note:
This is what I have for my htdocs/.htaccess for A and /var/www/html/.htaccess (hidden file) for B ...

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Hope this helps! Peace!

update your .htaccess

RewriteEngine on
RewriteBase /home/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM