0

I have the following .htaccess file:

AddDefaultCharset utf-8
RewriteEngine on
Options +SymLinksIfOwnerMatch
RewriteBase /

# redirect all www-requests to no-www
# -
RewriteCond %{HTTP_HOST} ^www\.site\.com$ [NC]
RewriteRule ^(.*)$ http://site.com/$1 [R=301,L]

# redirect all home pages to / (root)
# -
RewriteCond %{THE_REQUEST} ^.*/index\.(php|html?)
RewriteRule ^(.*)index\.(php|html?)$ /$1 [R=301,L] 

# remove trailing slash from dirs
# -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ /$1 [R=301,L]

# automatically add index.php when needed
# -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|login\.php|reg\.php|robots\.txt|css/|js/)
RewriteRule ^(.*)$ /index.php [L]

The .htaccess file should do the following (for SEO):

  1. Conversion to no-www (http://www.site.com should become http://site.com)
  2. All URIs with trailing slashes should convert to no-trailing-slash: http://site.com/me/ should be redirected http://site.com/me
  3. All URIs with index.php/index.html should convert to just nothing: http://site.com/admin/index.php or http://site.com/admin/ should be eventually displayed as http://site.com

However the current version of .htaccess results in a cyclic redirection when trying to access (http://site.com/admin). The real document that should be fetched by browser is http://site.com/admin/index.php.

Can anyone please help me with this issue?

4

1 回答 1

1

有一个名为mod_dir的模块会自动加载,它会导致对缺少尾部斜杠的目录的请求使用尾部斜杠重定向。您可以使用该DirectorySlash指令将其关闭,但请注意关闭时的安全警告。如果您将其关闭并且不会加载默认索引,则会出现信息泄露安全问题。但是,您的 lats 规则(看起来像)它会这样做,尽管不正确。

首先,关闭DirectorySlash

DirectorySlash Off

然后您需要将最后一条规则更改为:

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/index.php -f
RewriteRule ^(.*)$ /$1/index.php [L]
于 2013-07-18T21:35:24.907 回答