[英]Why is htaccess redirect not working when URL variable is NOT included?
[英]Why is my .htaccess redirect url not working
当有人访问我的网站时,我试图更改我的网址,因此非 www 重定向到 www ... http://example.com到http://www.example.com
我找到了这个代码
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) http://www.example.com/$1 [R=301]
但是当我将它添加到我的 .htaccess 时,我收到一个错误......这是错误的代码吗?? 我如何将它添加到我的 .htaccess 而不出现错误?
我的.htaccess
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)$ / profile.php?username=$1
将以下行添加到您的 .htaccess 文件中;
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
来源:
您可以在RewriteEngine On
下方添加:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
使用以下代码覆盖您的 .htacess 文件。
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)$ / profile.php?username=$1
.htaccess规则的更多理解:
http://www.web-technology-experts-notes.in/2014/02/htaccess-code-snippets-example.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.