[英]Permanently (301) redirect all urls to homepage with htaccess
I have a website with lots of page and I want all pages/urls will be permanently redirected (301) to homepage by htaccess.我有一个有很多页面的网站,我希望所有页面/网址都将通过 htaccess 永久重定向(301)到主页。 Can we please let me how could I achieve this?
我们可以请让我怎么能做到这一点?
I want something like that.我想要那样的东西。
mywebsite.com
to https://www.mywebsite.com/
mywebsite.com
到https://www.mywebsite.com/
mywebsite.com/page
to https://www.mywebsite.com/
mywebsite.com/page
到https://www.mywebsite.com/
mywebsite.com/assets/img.jpg
to https://www.mywebsite.com/
mywebsite.com/assets/img.jpg
到https://www.mywebsite.com/
Here is my current htaccess lines这是我当前的 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>
Thank you谢谢
Converting my comment to answer so that solution is easy to find for future visitors.将我的评论转换为答案,以便将来的访问者轻松找到该解决方案。
You may use this single rule:你可以使用这个单一的规则:
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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.