[英]Need help in htaccess redirect in a php project
I want to redirect mydomain.com and www.mydomain.com to http://www.mydomain.com/index 我想将mydomain.com和www.mydomain.com重定向到http://www.mydomain.com/index
I am using that code in htaccess file but not working 我正在htaccess文件中使用该代码,但无法正常工作
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteCond %{HTTP_HOST} ^www.mydomain.com
RewriteRule ^(.*)$ http://www.mydomain.com/index [r=301,L]
I have also try 我也尝试过
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule ^(.*)$ http://www.mydomain.com/index [r=301,L]
RewriteCond %{HTTP_HOST} ^www.mydomain.com
RewriteRule ^(.*)$ http://www.mydomain.com/index [r=301,L]
But not working so Please help me 但无法正常工作,请帮助我
You're missing 2 things. 您错过了两件事。
[OR]
flag in your conditions, or simply combine the regex [OR]
标志,或仅将正则表达式组合在一起 You are causing a redirect loop so you need to not redirect /index
您正在引起重定向循环,所以你需要不重定向
/index
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ [NC] RewriteCond %{REQUEST_URI} !^/index RewriteRule ^(.*)$ http://www.mydomain.com/index [r=301,L] RewriteCond%{HTTP_HOST} ^(www。)?mydomain.com $ [NC] RewriteCond%{REQUEST_URI}!^ / index RewriteRule ^(。*)$ http://www.mydomain.com/index [r = 301, L]
Or if you only want to redirect requests for the root : 或者,如果您只想重定向对根的请求:
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain.com$ [NC]
RewriteRule ^$ http://www.mydomain.com/index [r=301,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.