Go Back   vb.org Archive > Community Discussions > Forum and Server Management
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-20-2009, 07:17 PM
Brother Malachi Brother Malachi is offline
 
Join Date: Jun 2008
Posts: 208
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 04-20-2009, 07:25 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite\.com
RewriteRule (.*) http://www.yoursite.com/$1 [L,R=301]
Reply With Quote
  #3  
Old 04-20-2009, 07:32 PM
Brother Malachi Brother Malachi is offline
 
Join Date: Jun 2008
Posts: 208
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Super quick response! Thanks Lynne.

I already have few other rules in there, does it matter what order they go in?
Reply With Quote
  #4  
Old 04-20-2009, 07:33 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't think so.
Reply With Quote
  #5  
Old 04-20-2009, 07:42 PM
Brother Malachi Brother Malachi is offline
 
Join Date: Jun 2008
Posts: 208
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #6  
Old 04-21-2009, 10:34 PM
kermit2 kermit2 is offline
 
Join Date: Jun 2008
Posts: 117
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #7  
Old 04-25-2009, 09:55 AM
RedSpiral RedSpiral is offline
 
Join Date: Apr 2009
Location: England
Posts: 19
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I normally use this:

Code:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Reply With Quote
  #8  
Old 04-26-2009, 02:18 PM
BSMedia BSMedia is offline
 
Join Date: Feb 2009
Posts: 454
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by hammerhead24 View Post
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.
Thats a server side setting and you'll have to tell your hosting company to either disable it or inform your users to update your bookmarks. the /~name is generally used when the domain is still propagating over to the new DNS, and shouldn't be used afterwards.
Reply With Quote
  #9  
Old 04-29-2009, 04:30 PM
Carnage Carnage is offline
 
Join Date: Jan 2005
Location: uk
Posts: 760
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #10  
Old 05-01-2009, 12:33 AM
Ryan Ashbrook's Avatar
Ryan Ashbrook Ryan Ashbrook is offline
 
Join Date: Dec 2002
Location: Cincinnati, Ohio
Posts: 422
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
if ( preg_match '#\/~name\/\/forums\/#ise'$_SERVER['REQUEST_URI'] ) )
{
    
$uri str_replace '/~name/forums/'''$_SERVER['REQUEST_URI'] );
    
header 'Location: http://www.mysite.com/forums/' $uriTRUE301 );

Remember to replace all instances of ~name and mysite.com with what they should be.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:58 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04011 seconds
  • Memory Usage 2,255KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete