[英]Rewriting URL in CodeIgniter
我想在codeigniter中使用.htaccess重寫URL,但無法正常工作。 你能把它弄清楚嗎? 想要從以下位置更改URL:
www.site.com/mauritius_holiday_rentals/apartment/anyname
至
www.site.com/mauritius_holiday_rentals/anyname
我當前的.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]
前四行是從正常工作的URL中刪除index.php。
如果將路由文件設置為訪問新URL,並且您想為舊URL設置重定向,則在.htaccess中使用以下代碼。 否則,請讓我詳細了解您想做什么。
RewriteEngine on
RewriteBase /
RewriteRule /mauritius_holiday_rentals/apartment/$1 /mauritius_holiday_rentals/$1 [R=301,L]
Routes.php配置文件代碼
$route['mauritius_holiday_rentals/(:any)']="mauritius_holiday_rentals/apartment/$1";
讓我知道是否有問題。
嘗試使用codeigniter路由系統https://www.codeigniter.com/user_guide/general/routing.html
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.