1

我已经搜索过,虽然我发现很多线程都关闭了,但没有一个是我正在寻找的......

在我的网站上,比如说 example.com,我创建了子域 secure.example.com

该子域将具有 SSL。

我想要做的是将请求重定向到https://secure.example.com/path/到 www.example.com/path/,同时保持 url 显示为https://secure.example.com/path/

请注意 subdomain.example.com 的目的是用于 SSL,因此上面的重定向需要与 SSL 一起使用

我想在 htaccess 中使用其他一些重定向:1)将非 www 重定向到 www 忽略子域(因此 secure.example.com 不会变成 www.secure.example.com) 2)将 /index.php 重定向到/ 3) 最后但同样重要的是,在secure.example.com 上强制使用SSL

此外,购物车软件还有额外的 htaccess 功能和 SEO 语句,如下所示。

我当前的根 htaccess:

# Prevent Directoy listing 
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini|log)">
 Order deny,allow
 Deny from all
</FilesMatch>

# Turn Rewrite Engine On
RewriteEngine On

## index.php to root
Options +FollowSymlinks
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L] 

## non-www to www ignore subdomains
RewriteCond %{HTTP_HOST} ^example.com [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
4

1 回答 1

1

好吧,特别是https://secure.example.com/path/对于显示在 找到的内容的 url http://www.example.com/path/,您可以做 2 件事。最好的情况是,如果这 2 个域是从同一个文档根目录提供的:

它们位于同一主机和同一文档根目录上。子域实际上是根设置下带有子域的子文件夹。在我的主机的帮助下,我们现在可以正确解析并安装 SSL。

子目录可能有问题,因为它可能无法自己的文档根目录中重写。例如:

  • -> 文档根目录
  • www.example.com -> /path/to/htdocs
  • secure.example.com -> /path/to/htdocs/secure

如果您有一个 .htaccess 文件/path/to/htdocs/secure来重写对https://secure.example.com/. 这里的问题是您需要重写到父目录,而 apache 不会让您这样做。如果是相反的方式,您可以重写对http://www.example.com/to 的请求/secure。此外,如果两个域具有相同的文档根,您也可以重写。但如果安全是 www 的文档根目录的子目录,则不是。

我的主机说安装了 mod_proxy。我的 Apache 配置显示这些已安装: proxy_module (static) proxy_connect_module (static) proxy_ftp_module (static) proxy_http_module (static) proxy_ajp_module (static) proxy_balancer_module (static)

这意味着您至少可以使用Prewrite 标志将请求发送到 mod_proxy,因此您可以执行以下操作:

RewriteEngine On
RewriteRule ^path/$ http://www.example.com/path/ [L,P]

在secure.example.com 的文档根目录中的htaccess 文件中。那只会专门代理 URI /path/,而不是类似/path/foo/bar.html. 如果您想要以 开头的所有内容/path/,那么您可以匹配它:

RewriteRule ^path/(.*)$ http://www.example.com/path/$1 [L,P]

如果存在重定向问题,您可能需要ProxyPass改用:

ProxyPass / http://www.example.com/
ProxyPassReverse / http://www.example.com/

除了重写位置标头之外,它做同样的事情,因此重定向也被代理。

于 2012-08-15T04:02:58.393 回答