htaccess重定向

时间:2012-08-03 13:49:02

标签: url redirect

我想从“子目录”网址中删除文件名,只显示浏览器网址中的子目录。

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

变为:

www.domain.com.au/login/

我尝试过本网站和互联网的各种解决方案,但都没有。

如果可能的话,我想将新的重定向放在root 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重定向的所有解决方案都失败了。

此致

彼得

1 个答案:

答案 0 :(得分: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]   
相关问题