[英]CodeIgniter + mod_rewrite url rewrite error
我已經在Windows(使用WampServer)上使用CodeIgniter和mod_rewrite(僅用於抽象索引)創建了一個應用程序。 在那種環境下,該應用程序可以正常運行,一切都應該順利進行。 但是,當我將其移植到生產服務器(Linux)時,重寫過程剛剛停止工作。
乍一看,在我看來linux文件系統的“區分大小寫”是無禮的。 但是重命名包含錯誤的文件后,問題仍然存在。
事實是。 無論我調用哪個url,重寫都會繼續調用/index.php。
這是我的.htaccess內容:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
RewriteRule .\svn\* - [F]
我的應用程序的文件夾結構為:
doc_root
- application
-controllers
-c.php
- .htaccess
- index.php
(... everything else is codeigniter's default)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
以Kenzo的答案為基礎,並進行了進一步的研究,我得出了上面的配置。 它本身並不能完全解決整個問題,但是重寫部分已被完全解決。 整個問題的一部分是由於重寫引擎不知道如何正確重定向,另一部分是文件系統的“區分大小寫”。 我不知道這是否是最好的解決方案,但是我創建了一些指向主控制器和模型的符號鏈接,並且一切正常。 該符號鏈接方法有效,原因是我的控制器文件名為“ c.php”,因此我創建了“ C.php”符號鏈接,並且每個請求都可以完成,而不必擔心區分大小寫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.