The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Using mod rewrite to force people to use "www" in the url
I'm trying to force an auto redirect on those that don't use "www" in their url. Does anyone know how to accomplish this using .htaccess and mod rewrite?
The reason being that vb uses cookies to store login data. So if I goto http://www.myforum.com and login, then goto http://myforum.com I will still be logged out since the cookies stored were for the "www" domain. This becomes a huge issue with several mods that use hand written links and not dynamically generated. (I.e. instead of using the current address (meaning, it will use "www" in the url if the current url has it), they use a hand written one...regardless of whether the link has "www" in it or not. I.E. one of the mods inserted a link into my navbar that is always without a "www". Therefore, users often login with "www" in the url, then click on the link and are logged out. |
#2
|
||||
|
||||
Code:
RewriteEngine on RewriteCond %{HTTP_HOST} ^yoursite\.com RewriteRule (.*) http://www.yoursite.com/$1 [L,R=301] |
#3
|
|||
|
|||
Super quick response! Thanks Lynne.
I already have few other rules in there, does it matter what order they go in? |
#4
|
||||
|
||||
I don't think so.
|
#5
|
|||
|
|||
Awesome, it worked!
:high five: --------------- Added [DATE]1240261256[/DATE] at [TIME]1240261256[/TIME] --------------- One more quick question. Our hosting provider gives us access via "/~name/" appended to the end of the url for some reason. So when we go to www.mysite.com/~name/ the root directory loads and www.mysite.com/~name/forums/ loads the forum directory. I tried writing a condition that would detect the "~name" and remove it from the url but apparently the server treats www.mysite.com/~name/ as www.mysite.com and .htaccess isn't able to detect the "~name" in it. (unless I wrote the condition wrong) Any idea how this can be fixed? The reason THIS is an issue, is because some of the users still use the url with "~name" in it since that is what they bookmarked. |
#6
|
|||
|
|||
Just as a side note, if you set the cookie domain to .mysite.com (with a dot at the beginning) via the ACP, your cookies will be good for mysite.com, www.mysite.com, whatever.mysite.com etc
|
#7
|
|||
|
|||
I normally use this:
Code:
RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] |
#8
|
|||
|
|||
Quote:
|
#9
|
|||
|
|||
Is it a dedicated server?
As for the original query; A slightly better way than mod rewrite is to use your dns settings. If you set the @ record to redirect to www using a 301 redirect; It'll have the additional effect of consolidating search engine ranks over the two sub domains. How you do this depends on your dns host |
#10
|
||||
|
||||
I use this method, you can try it but I can't garauntee it'll work without some adjustments.
Create a plugin and place it on the global_start hook with the following code: PHP Code:
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|