协助提炼.htaccess

时间:2010-11-03 18:58:39

标签: .htaccess

我正在努力优化.htaccess文件中的代码,但在重写从httpshttp的子目录请求的网址时遇到问题。这是我的尝试:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SERVER_PORT} =443
RewriteCond %{REQUEST_URI} !\.(js|css|jpe?g|png|bmp|gif)$ [NC]
RewriteRule !^dashboard(/.*)?$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

RewriteCond %{SERVER_PORT} =80
RewriteRule ^dashboard(/.*)?$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

此代码适用于对根网址的https请求,但是当请求进入时,例如https://example.com/sub,网址将被单独存在,并显示无效的证书警告。

我的目的是重写除dashboard子目录之外的所有请求。

1 个答案:

答案 0 :(得分:0)

尝试在RewriteCond中添加dashboard子句:

RewriteCond %{SERVER_PORT} =443
RewriteCond %{REQUEST_URI} !\.(js|css|jpe?g|png|bmp|gif)$ [NC]
RewriteCond %{REQUEST_URI} !>dashboard [NC]
RewriteRule ^.*$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]