2012-08-03 119 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