[英]How to redirect from the www to the non-www version in an HTACCESS file?
我已经在我的 Linux 服务器中安装了 Laravel 5.2 并且我通过修改 HTACCESS 文件几乎没有做到这一点,所以现在我试图从 www 重定向到非 www 版本我的意思是像来自 www.example 的 stackoverflow。 com >>TO>> example.com ,但我担心因为我可能会崩溃我的服务器所以请帮助解释代码:
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/$1
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/$1 [L,NC]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.