用htaccess进行URL重写的问题是什么 [英] What is the Poblem in my URL Rewriting with htaccess
问题描述
我希望我的网站从example.com自动重定向到http://www.example.com
为此,我在.htaccess文件中使用了以下代码
I want my site to be automatically redirected from example.com to http://www.example.com
For this Purpose I have used the following code in .htaccess file
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.example.com/$1 [L,R]
但这不起作用,并且我不会在此代码中发现任何问题.
任何人都可以指出问题所在吗?
注意:我在这里有此代码的代码
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html [ ^ ]
But it is not working and I am not gonna find any problem in this code.
Can Any one Point out the problem.
Note: I have code this code from here
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html[^]
推荐答案
RewriteRule ^/(.*)http://www.example.com/
RewriteRule ^/(.*) http://www.example.com/
1 [L,R]
但这不起作用,并且我不会在此代码中发现任何问题.
任何人都可以指出问题所在吗?
注意:我在这里有此代码的代码
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html [ ^ ]
But it is not working and I am not gonna find any problem in this code.
Can Any one Point out the problem.
Note: I have code this code from here
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html[^]
幸运的是,我找到了解决方案.我在.htaccess中使用了以下代码,现在可以正常使用了.
Fortunately, I have found the solution. I used the following code in .htaccess and now it is working fine.
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)
这篇关于用htaccess进行URL重写的问题是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!