如何从 www 重定向到 HTACCESS 文件中的非 www 版本?

How to redirect from the www to the non-www version in an HTACCESS file?

我已经在我的 Linux 服务器中安装了 Laravel 5.2 我通过修改 HTACCESS 文件很难做到这一点,所以现在我正在尝试从 www 重定向到非-www 版本我的意思是像来自 www.example.com >>TO>> example.com 的 Whosebug,但我担心因为我可能会崩溃我的服务器所以请帮助解释代码:

RewriteEngine on 

# I changed my website real name to example
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 

RewriteCond %{REQUEST_URI} !^/example/ 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.*)$ /example/ 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
RewriteRule ^(/)?$ example/index.php [L]

提前致谢

您可以试试这些规则:

RewriteEngine on 

# I changed my website real name to example
RewriteCond %{HTTP_HOST} ^www\.(.+)$ 
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301,NE]

RewriteRule ^/?$ example/index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(?!example/)(.*)$ example/ [L,NC]