简体   繁体   English

在CodeIgniter中重写URL

[英]Rewriting URL in CodeIgniter

I want to rewrite URL using .htaccess in codeigniter but it's not working. 我想在codeigniter中使用.htaccess重写URL,但无法正常工作。 Can you please figure it out. 你能把它弄清楚吗? Want to change URL from: 想要从以下位置更改URL:

www.site.com/mauritius_holiday_rentals/apartment/anyname

to

www.site.com/mauritius_holiday_rentals/anyname

My current .htaccess file contains: 我当前的.htaccess文件包含:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 
RewriteRule ^mauritius_holiday_rentals/([A-Za-z0-9-]+)/?$ mauritius_holiday_rentals/apartment/$1 [L,QSA]

First four line is for removing index.php from URL which is working fine. 前四行是从正常工作的URL中删除index.php。

If routes file is set to access new url and you want to set redirection for old URLs then Use following code in .htaccess. 如果将路由文件设置为访问新URL,并且您想为旧URL设置重定向,则在.htaccess中使用以下代码。 otherwise let me know in detail what you want to do. 否则,请让我详细了解您想做什么。

RewriteEngine on
RewriteBase /
RewriteRule /mauritius_holiday_rentals/apartment/$1 /mauritius_holiday_rentals/$1 [R=301,L]

Routes.php config file code Routes.php配置文件代码

$route['mauritius_holiday_rentals/(:any)']="mauritius_holiday_rentals/apartment/$1";

Let me know if any problem. 让我知道是否有问题。

 RewriteEngine On    
 RewriteBase /yourProjectName/    
 RewriteCond $1 !^(images|stylesheets|javascript)    
 RewriteCond %{REQUEST_FILENAME} !-f    
 RewriteCond %{REQUEST_FILENAME} !-d    
 RewriteRule ^(.*)$ /yourProjectName/index.php?/$1 [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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