apache basic auth在.htaccess

时间:2015-07-23 20:36:19

标签: php apache .htaccess authentication

重写工作正常,直到我们将auth添加到htaccess。身份验证是否正确?为什么在添加auth之前会重写工作?

请求没有身份验证的站点控制器的参数:

[id] => 433    [type] => city

auth添加并且用户进行身份验证后的参数:

[site/query]

不使用身份验证的示例查询网址:

http://www.website.com/site/query?type=city&id=433

底部有基本身份验证的.htaccess:

# any visits not coming from this official URL should be rerouted; AJAX cross-domain, www.website.com is not the same as our.company.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.website\.com$ [NC]
RewriteRule ^(.*)$ http://www.website.com/$1 [R=301,L]

# route all requests that are NOT static files, through index.php to make the /nice/urls/ work
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]

# disable file listings for directories
Options -Indexes

# disable the fetching of .phtm
<Files ~ "\.phtml$">
  Order allow,deny
  Deny from all
</Files>

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

AuthType Basic
AuthName "Password required"
AuthUserFile /maps/scorp/main/.htpasswd
Require valid-user

1 个答案:

答案 0 :(得分:1)

我对你的好问题没有答案,但我希望我找到了解决方案。 :)

你的 .htaccess 中的恕我直言,授权将占据优势。这有点棘手但你可以通过将“Require valid-user”指令包含在块&lt; Files&gt;中来打破优先级。 E.g:

<Files "*.phtml">
    Require valid-user
</Files>