所以我玩.htaccess在我的codeigniter應用程序有乾淨的網址。htaccess問題導致內部服務器錯誤太多重定向
總之,我試圖:
1)除去的index.php在網址(重定向永久)
http://localhost/directory/index.php*
to
http://localhost/directory/*
http://my.domain.com/index.php*
to
http://my.domain.com/*
2)重寫請求某些控制器到index.php/[ CONTROLLER_NAME]
http://localhost/directory/controller1*
to
http://localhost/directory/index.php/controller1*
http://my.domain.com/controller2*
to
http://my.domain.com/index.php/controller2*
我htaccess文件目前是這樣的:
Options +FollowSymlinks
RewriteEngine On
#RewriteBase/
# Redirect index.php
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule ^(.*)index\.php((/)(.*))?$ /$1/$4 [R=301,L]
第一個問題:
,這並不爲http://localhost/dir/index.php/controller1
工作。 不是重定向到http://localhost/dir/controller1
,重定向到http://localhost//controller1
# Rewrite CI certain controllers
RewriteCond %{THE_REQUEST} directory/(home|other_controller) [NC]
RewriteRule ^(.*)(home|other_controller)(.*)$ /$1index.php/$2$3 [NC,L]
第二個問題($1
返回空字符串):
這是行不通的http://localhost/dir/home
給內部服務器錯誤(過多的重定向)。 但如果我測試添加R=301
的代碼,它成功重定向到http://localhost/dir/index.php/home
。但這不是我的重定向意圖,我只需要重寫它。
請指教.. :)
謝謝@Repox,但是這個重寫'http:// localhost/directory/controller'到'http:// localhost/index.php/controller',而不是'http:// localhost/directory/index.php/controller' –
簡單...只需添加它...或者在htaccess中設置一個RewriteBase – Brian
@Brian,是否有可能通過正則表達式添加它,而不顯式編寫目錄名稱或重寫基址?所以這個.htaccess文件將是可移植的本地和生產.. –