Eve For Enterprise    Eve Support Community    Forums  Hop To Forum Categories  Eve Community  Hop To Forums  Customization Ideas    Cookie Woes? Quick Tip
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Groupee Member
Posted
A few of you probably already know this but I thought I would post it as a helpful tip for others.

I got tired of checking for the 'eve' cookie to do quick things for my users only to have them complain about not seeing 'results'. This happens when they would come to a page using www.domain.com/... instead of domain.com/...

I remembered that Apache has a mod_rewrite module but hadn't used it in some time. After a couple of attempts I came up with this. It will make sure you can always see that cookie if it is available.

Here is what you need to do :

1 Create a file called .htaccess
2 Put the following code in it :
rewriteEngine On
rewriteCond %{HTTP_HOST} ^(www\.)?www.domain.com$ [NC]
rewriteRule ^(.*)$ http://domain.com/$1 [L,R=permanent]

3 Upload it to your root html directory

Anytime a visitor types in or follows a link to www.yourdomain.com (and whatever else) it will get rewritten to yourdomain.com (and whatever else).

Quick question for those of you who already knew this:

1. Is there a speed issue or noticeable delay when doing this? I tested it a bunch and couldn't perceive any problems.
 
Posts: 281 | Registered: May 26, 2002Reply With QuoteEdit or Delete MessageReport This Post
Groupee Member
Picture of Jamin
Posted Hide Post
Hehe. I posted my reply to this topic on Evedev, but I suppose I'll post it here too, to get a second opinion...

I was having the exact same problem, but I took a slightly different approach to it (since I had no idea how to work mod_rewrite). At the very top of my application script, I have the following:
if ($_SERVER["HTTP_HOST"] == "www.se7enet.com") {
    if ($_SERVER["QUERY_STRING"] != "") { $query = "?".$_SERVER["QUERY_STRING"]; }
    die(header("Location: http://se7enet.com/index.php$query"));
}


So is it better/faster/safer to use the htaccess file? Or is PHP ok too?

---Jamin


God called in sick today.
Se7enet
 
Posts: 297 | Location: college | Registered: December 18, 1999Reply With QuoteEdit or Delete MessageReport This Post

Craftsman
Posted Hide Post
quote:
Originally posted by Jamin:
So is it better/faster/safer to use the htaccess file? Or is PHP ok too?

---Jamin


I think it's about the same as far as speed goes. I think .htaccess is better if you have multiple files you want to have redirected.



testing sigs
 
Posts: 977 | Location: Seattle | Registered: January 28, 2002Reply With QuoteEdit or Delete MessageReport This Post
Groupee Member
Posted Hide Post
I'm going to be doing stuff on most of the pages on my site so the mod_rewrite will work best for me. I've been thinking about this some and although I'm no Apache / PHP expert I would think the Apache way would be faster:

Apache Mod_Rewrite

URL Request www.domain.com/whatever
URL Rewrite domain.com/whatever

PHP Rewrite

URL Request www.domain.com/whatever.php
Server Parses PHP Code
PHP Rewrites Location

I doubt the speed savings is noticeable though.
 
Posts: 281 | Registered: May 26, 2002Reply With QuoteEdit or Delete MessageReport This Post
Groupee
Posted Hide Post
The apache method is faster, but not noticably in most cases.

1) Server gets request
2) Server parses htaccess (if any)
3) Server redirects/rewrites as necessary
4) Server delivers content

1) Server gets request
2) Server parses htaccess (if any)
3) Server parses PHP script
4) Server redirects as necessary
5) Server delivers content
 
Posts: 3880 | Location: Seattle, WA | Registered: January 01, 2000Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 

Eve For Enterprise    Eve Support Community    Forums  Hop To Forum Categories  Eve Community  Hop To Forums  Customization Ideas    Cookie Woes? Quick Tip