2012-08-03 93 views
0

我想從「子目錄」URL中刪除文件名,只顯示瀏覽器URL中的子目錄。htacces重定向

所以: www.domain.com.au/login/public_index.php

變爲:

www.domain.com.au/login/ 

我從這個網站和互聯網嘗試了各種解決方案,但都沒有奏效。

如果可能我想把新的重定向在根htaccess文件?而不是在子目錄htaccess文件?

*只是在htaccess文件的情況下其他重定向是與任何新的子目錄重定向衝突,這裏是在htaccess文件的其他(和必要的)重定向執行重要的工作:

#(1) A redirection to remove root level index.php from the url 
# Redirect index.php to domain.com.au 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ 
RewriteRule ^index\.php$ http://www.domain.com.au/ [R=301,L] 

#(2) 
# Redirect domain.com.au to www.domain.com,au 
RewriteCond %{HTTP_HOST} ^domain.com.au [NC] 
RewriteRule ^(.*)$ http://domain.com.au/$1 [L,R=301] 

#(3) 
# Force SSL on login directory 
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} login 
RewriteRule ^(.*)$ https://www.domain.com.au/$1 [R,L] 

任何幫助將不勝感激,因爲所有添加新子目錄URL重定向的解決方案都失敗了。

問候,

彼得

回答

0

你可以做同樣的事情您在#(1)做了什麼:

#(4) 
# remove public_index.php 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+)/public_index\.php\ HTTP/ 
RewriteRule public_index\.php$ http://www.domain.com.au/%1/ [R=301,L] 

# internally add it back 
RewriteCond %{REQUEST_URI} ^/([^/]+)/?$ 
RewriteCond %{DOCUMENT_ROOT}/%1/public_index.php -f 
RewriteRule^/%1/public_index.php [L] 

這對任何子目錄,但如果你只在login感興趣,那變得更容易:

#(4) 
# remove public_index.php 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /login/public_index\.php\ HTTP/ 
RewriteRule public_index\.php$ https://www.domain.com.au/login/ [R=301,L] 

RewriteRule ^/?login/?$ /login/public_index.php [L] 
+0

感謝您的幫助!令人驚歎的是,我節省了數小時不必再深入學習「另一種」語言的時間。 – Peter 2012-08-12 17:50:21