簡體   English   中英

在Codeigniter中使用.htaccess將一個URL重定向到另一個URL

[英]Redirect one url to another url using .htaccess in codeigniter

我正在嘗試重定向這些URL:

http://www.example.com/welcome/index

http://www.example.com/welcome

http://www.example.com/index.php

到此URL:

http://www.example.com/

使用重寫規則。

我已經嘗試過了(這是行不通的):

Redirect 301 http://www.example.com/welcome/index$ http://www.example.com/

請在您的路線.htaccess文件中添加以下代碼

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule (.*) http://example.com/$1 [R=301,L] 

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

另外,檢查您的$config['base_url']並添加您的基本URL:

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

然后它將像魅力一樣工作,您將重定向到另一個沒有index.php的控制器

Example:  http://localhost/project/home

使用索引功能:

 www.example.com/welcome/index 

如果需要在URL中使用索引功能,為此,請在路由文件中設置路由。

請按上面的方法進行檢查

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM