简体   繁体   English

使用 .htaccess 重定向到 www 不重定向

[英]Redirect to www with .htaccess not redirecting

Im have absolutely no experience with .htaccess and i tried something today.我对 .htaccess 完全没有经验,我今天尝试了一些东西。 I basicly wanted all my pages starting with http://www .我基本上想要所有以http://www开头的页面。 to redirect to http://重定向到 http://

so i did a search on the internet and found this link:所以我在互联网上搜索并找到了这个链接:

http://forum.joomla.org/viewtopic.php?p=2437275 http://forum.joomla.org/viewtopic.php?p=2437275

again i had absolutely no idea what i was doing and i just copy pasted this再次,我完全不知道我在做什么,我只是复制粘贴这个

RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*) http://example.com/$1 [L,R=301]

into a .htaccess file in my public_html directory进入我的 public_html 目录中的 .htaccess 文件

i tested going into a http://www site but nothing happened, so i just deleted everything in the .htaccess file as it was in the beginning, totally bank.我测试了进入http://www站点,但什么也没发生,所以我只是删除了 .htaccess 文件中的所有内容,就像一开始一样,完全是银行。

so i tested this所以我测试了这个

# Redirect to www
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

and then this:然后这个:

# Redirect to non-www
RewriteCond %{HTTP_HOST} !^(example\.com)?$
RewriteRule (.*) http://example.com/$1 [R=301,L]

just like the article says就像文章说的

But now a few hours later i notice something really strange.但现在几个小时后,我注意到了一些非常奇怪的事情。 One of my ajax calls from jquery takes like 1 minute to complete.. Is there anything i can do to undo this?我从 jquery 发出的 ajax 呼叫之一需要大约 1 分钟才能完成。我能做些什么来撤消这个? Its almost like something does an infinite loop like the article says.它几乎就像文章所说的那样进行无限循环。 And i have no idea what to do.我不知道该怎么做。

Everything works on localhost..一切都在本地主机上运行..

Regards, Alexander问候,亚历山大

A more optimized version, which don't have domain dependencies更优化的版本,没有域依赖

Just simple copy and paste in any domain and it will work.只需简单地复制并粘贴到任何域中,它就会起作用。

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

You have to have你必须有

RewriteEngine on

At the beginning of your file.在文件的开头。

This may be obvious but since you have no experience, just in case, you have to replace example.com with your domain name.这可能很明显,但由于您没有经验,以防万一,您必须将 example.com 替换为您的域名。

Be sure you actually have and Apache server.确保您确实拥有 Apache 服务器。

Be sure to name your file ".htaccess" (with the dot, without the "")请务必将文件命名为“.htaccess”(带点,不带“”)

So, this should work:所以,这应该工作:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*) http://example.com/$1 [L,R=301]

I really doubt what you did on the .htaccess could slow down the AJAX call, check to see if the .htaccess is now empty, if it is, it will not affect it for sure.我真的怀疑你在 .htaccess 上所做的是否会减慢 AJAX 调用,检查 .htaccess 现在是否为空,如果是,肯定不会影响它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM