我正在使用Zend框架,其中有漂亮的URL控制器。跟随.htaccess起作用,但是它使SEO看到我们是一页的四个链接。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
我需要使用htaccess进行以下修复:
www.stackoverflow.com/nice-looking-url = https://www.stackoverflow.com/nice-looking-url
stackoverflow.com/nice-looking-url = https://www.stackoverflow.com/nice-looking-url
http://www.stackoverflow.com/nice-looking-url = https://www.stackoverflow.com/nice-looking-url
http://stackoverflow.com/nice-looking-url = https://www.stackoverflow.com/nice-looking-url
如何使用htaccess正确执行操作?因此上述输入网址可以通过https://www安全着陆。总是在前面?
答案 0 :(得分:1)
具有如下完整的.htaccess权限:
RewriteEngine On
## add www and turn on https in same rule - main domain
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
## turn on https in same rule - sub domain
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
请确保使用新的浏览器来测试您的更改,以避免旧的浏览器缓存。