所以我正在重定向两件事。一个是 SSL 和域,我有一个带有 .httaccess 的静态应用程序来执行此操作:
# https/domain forwarding
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.org$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC,OR]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
这似乎有效。例如,如果我测试curl -I http://mydomain.com/
我得到,
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Fri, 07 Jun 2013 11:43:17 GMT
Content-Type: text/html; charset=iso-8859-1
Connection: keep-alive
Location: https://www.mydomain.com/
它也适用于浏览器。但是我也想重定向
http://www.mydomain.com/cat/some-category/some-long-slug _ _
==> https://www.mydomain.com/ category/name /some-long-slug`
所以为了避免重定向循环,我编辑了 apache httpd.conf,如下所示:
<Location "/cat/used-cars/">
RewriteCond %{REQUEST_URI} ^www.mydomain.com/cat/used-cars/$
RewriteRule ^(.*)$ https://www.mydomain.com/category/cars/$1 [R=301,NC]
</Location>
但是,当我用 curl -I http://mydomain.com/cat/used-cars/测试它时, 我看到:
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Fri, 07 Jun 2013 11:48:33 GMT
Content-Type: text/html; charset=iso-8859-1
Connection: keep-alive
Location: https://www.mydomain.com/car/used-cars/
所以它知道它必须重定向但它没有?浏览器会给出 404,因为该地址不再存在。任何关于我可能做错的提示都非常受欢迎。