问题
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