我有一个有很多页面的网站,我希望所有页面/网址都将被 htaccess 永久重定向(301)到主页。我们可以让我如何实现这一目标吗?
我想要这样的东西。
mywebsite.com
到 https://www.mywebsite.com/
mywebsite.com/page
到 https://www.mywebsite.com/
mywebsite.com/assets/img.jpg
到 https://www.mywebsite.com/
这是我当前的 htaccess 行
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
谢谢
答案 0 :(得分:1)
将我的评论转换为答案,以便将来的访问者轻松找到解决方案。
您可以使用这个单一规则:
RewriteEngine On
# redirect to landing page if it is
# non-www or non-https or any URL other than landing page
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{REQUEST_URI} ^/.
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule . https://www.%1/ [R=301,L]