使用.htaccess删除codeigniter中的url段 [英] Remove url segment in codeigniter with .htaccess
问题描述
我将Codeigniter项目上载到/ dev文件夹,而旧网址是 http://example.com/dev
。但是现在我将项目移到了根文件夹。因此,更新后的网址为 http://example.com
。如何通过编辑 .htaccess
文件将旧网址重定向到新网址。我可以从网址中删除网址段 / dev /
,例如删除 index.php
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
我通过将以下代码添加到.htaccess中来尝试了此方法
i tried this method by adding the below code to .htaccess
RewriteEngine on
RewriteBase /
RewriteRule ^/dev/(.+)$ /$1 [L,QSA]
但是没有用
推荐答案
首先,请确保配置中的基本URL是正确的。
First of all, make sure the base URL in the config is correct.
$config['base_url'] = "http://example.com/";
之后,您可以尝试使用.htaccess
after that, you can try with .htaccess
将 RewriteRule ^ / dev /(.+)$ / $ 1 [L,QSA]
更改为下一行。
RewriteRule ^(。*)$ dev / $ 1 [L]
RewriteRule ^(.*)$ dev/$1 [L]
这篇关于使用.htaccess删除codeigniter中的url段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!