开发者

Redirect to www with .htaccess not redirecting

Im have absolutely no experience with .htaccess and i tried something today. I basicly wanted all my pages starting with http://www. to redirect to http://

so i did a search on the internet and found this link :

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

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.

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)?$开发者_JAVA技巧
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? 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.

Be sure you actually have and Apache server.

Be sure to name your file ".htaccess" (with the dot, without the "")

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜