我已经在我的Linux服务器上安装了Laravel 5.2而且我很难通过修改HTACCESS文件来实现它,所以现在我试图从www重定向到非www版本我的意思就像stackoverflow来自www.example.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]
提前致谢
答案 0 :(得分:1)
您可以尝试以下规则:
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]