Remove url segment in codeigniter with .htaccess

梦想与她 提交于 2019-12-11 07:27:07

问题


I uploaded a Codeigniter project to /dev folder and the old url was http://example.com/dev. But now i moved the project to root folder. So the updated url is http://example.com. How can i redirect old url to new url by editing .htaccess file. Can i remove the url segment /dev/ from url like removing index.php

i tried this method by adding the below code to .htaccess

RewriteEngine on
RewriteBase /

RewriteRule ^/dev/(.+)$ /$1 [L,QSA]

but didnt work


回答1:


use this as .htaccess file

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



回答2:


Please add following code in your .htaccess file.

DirectoryIndex index.php


<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
<IfModule mod_headers.c>
 Header set Access-Control-Allow-Origin "*"
</IfModule>
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php/$1 [L]



回答3:


First of all, make sure the base URL in the config is correct.

$config['base_url'] = "http://example.com/";

after that, you can try with .htaccess

change RewriteRule ^/dev/(.+)$ /$1 [L,QSA] to the following line.

RewriteRule ^(.*)$ dev/$1 [L]



来源:https://stackoverflow.com/questions/57266556/remove-url-segment-in-codeigniter-with-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!