High Rankings Search Engine Optimization ForumHigh Rankings Advisor Search Marketing Newsletter

Welcome Guest ( Log In | Register )

Important Announcement: *Written SEO Website Reviews Available*
 
Reply to this topicStart new topic
> Mod_redirect Or Mod_rewrite?, 301 redirects
greentea
post May 3 2005, 10:40 AM
Post #1


HR 2
**

Group: Banned
Posts: 26
Joined: 3-May 05
User's local time:
Jul 31 2010, 07:50 PM
Member No.: 7,341



Hi,

Our web has a big problem. It has thousands of html pages and about 100 to 200 of them have either moved to the root directory or been renamed over the years.

We have learned that anyone accessing the old urls can be directed to the new urls either through .htaccess, mod_redirect or mod_rewrite. We had googled the whole day today and came away with the conclusion that .htaccess if not a good solution, and we should use either mod_redirect or mod_rewrite.

We would appreciate it very much if any kind soul here could offer:
1. your expert advice on whether mod_redirect or mod_rewrite is the best solution, and how we should implement it, and
2. sample code for mod_redirect or mod_rewrite, and where and how we should include them in our httpd.conf file. We are totally lost here.

Thank you in advance. :-)
Go to the top of the page
 
+Quote Post
Ron Carnell
post May 3 2005, 04:06 PM
Post #2


HR 6
Group Icon

Group: Moderator
Posts: 929
Joined: 24-July 03
User's local time:
Jul 31 2010, 07:50 PM
From: Michigan USA
Member No.: 17



I think there's just a tad bit of confusion over your potential options. It's not really a choice between .htaccess, mod_rewrite or mod_redirect, because all three of those don't quite correlate to each other. Your first choice is between mod_rewrite and mod_redirect. Then you have a choice of where you want to implement the rewrite or redirect, either in .htaccess or in httpd.conf.

So, if I may, let's rephrase your questions.

Between mod_redirect and mod_rewrite, which is better?

Mod_redirect, which most just call a standard redirect, is always the least server intensive and should be your first choice. It's the least server intensive, however, because it's also the least powerful -- and there are a lot of instances where it just won't do the job you need done. It doesn't handle query strings well, for example, and it can't easily change an aliased domain. If a standard redirect can do the job, use it. If it can't, then you have no choice but to use mod_rewrite instead.

Between .htaccess and httpd.conf, which is better?

Putting your rewrite or redirect in the httpd.conf is always the least server intensive and is usually your best choice. The httpd.conf file is read exactly once, when Apache is started, and almost literally becomes part of the web server. Your .htaccess file, on the other hand, is read for every single file requested. The advantage is that it's dynamic, meaning changes can be made without shutting down and restarting Apache, and you can also have multiple .htaccess files for different directories. The disadvantage, obviously, is that the web server can spend a lot of time just searching for and reading the .htaccess files.

Here's the irony. Most people can't use httpd.conf because they're on a shared server and don't have access to such a low-level configuration file. Those who can use httpd.conf are likely on a dedicated server . . . and probably are hurt very little by using .htaccess. Yea, they have more processor power, but even more importantly, the probably don't have 500 domains and 500 .htaccess files on the server. Ergo, instead of the server having to find and read .htaccess for every file request it typically will be able to pull it out of disk cache.

If you have to use .htaccess, or prefer to do so for flexibility, the redirect or rewrite commands are simply put in the file and will apply to the directory (and subdirectories) of where ever the file is placed. Piece of cake.

It's a little more difficult with httpd.conf, or at least a little different, because your redirect or rewrite commands will be place in blocks that tell Apache where to apply the commands. Blocks are similar to HTML containers, in that they have a beginning, an end, and something in the middle. Most of the time, you'll want to put your redirect/rewrite commands inside of the VirtualHost block that defines your domain. That's essentially the same as putting an .htaccess file in your root directory. It might look a bit like:

<VirtualHost 192.xxx.xxx.xxx>
ServerName yourdomain.com
DocumentRoot /home/domain/www
Redirect 301 /page.htm http://domain.com/other.htm
</VirtualHost>

There are dozens of different places to put your code in httpd.conf, of course, and tens of thousands of different ways to write the redirect or rewrite. Any samples beyond the most generic, therefore, will depend on what you want to accomplish.

p.s. Welcome to HR! (IMG:http://www.highrankings.com/forum/style_emoticons/default/smile.gif)
Go to the top of the page
 
+Quote Post
Randy
post May 3 2005, 06:58 PM
Post #3


Convert Me!
Group Icon

Group: Admin
Posts: 17,540
Joined: 17-August 03
User's local time:
Jul 31 2010, 06:50 PM
Member No.: 551



Excellent answer Ron ! (IMG:http://www.highrankings.com/forum/style_emoticons/default/appl.gif)

Another option --with that many pages that need to be redirected and if many of them are old enough that they wouldn't normally be found via the search engines or direct links-- might be to simply create a really good 404 Not Found error page. One that will easily allow people to find what they're looking for.

Of course if you wanted to you could also set up your 404 page so that it can include server side scripting and then detect the page someone coming from. With that information you could use a code solution to redirect people where they need to be if they're coming from specific pages.
Go to the top of the page
 
+Quote Post
greentea
post May 5 2005, 11:39 AM
Post #4


HR 2
**

Group: Banned
Posts: 26
Joined: 3-May 05
User's local time:
Jul 31 2010, 07:50 PM
Member No.: 7,341



Thanks Ron! You've enlightened not just us, but also many others who may be facing the same problems. (IMG:http://www.highrankings.com/forum/style_emoticons/default/smile.gif)

Just a few more questions. We have a dedicated server, let's call it orange.server.com, and it hosts a few domains, some with different IPs. If we were to use redirects in our httpd.conf, and assuming that we have the following 3 old pages to be redirected to the new pages, is the following code correct?

<VirtualHost 192.xxx.xxx.xxx>
orange.server.com ourdomain.com
DocumentRoot /home/domain/public_html
Redirect 301 /oldpage1.html http://www.ourdomain.com/newpage1.html
Redirect 301 /oldpage2.html http://www.ourdomain.com/newpage2.html
Redirect 301 /oldpage3.html http://www.ourdomain.com/newpage3.html
</VirtualHost>

Should the IP 192.xxx.xxx.xxx be the IP of our server or the IP of our domain? Do we still use the tags <VirtualHost 192.xxx.xxx.xxx></VirtualHost> even if the domain has a dedicated IP? And where is the best place in httpd.conf to place the code?

Two of our domains are sharing the same IP, and another three are sharing the same IP as the server. In such cases, how should we change the above code so that we can redirect old pages on these domains?

Also, will the above code work if we were to redirect an old domain name to a new domain name using domain pointing? E.g. olddomain.com's IP is 1.2.3.4 and newdomain.com's IP is 5.6.7.8. Let's say we use httpd.conf to redirect all traffic from olddomain.com to newdomain.com. If someone tries to access olddomain.com/oldpage.html will the above code redirect him to newdomain.com/newpage.html?

Thank you in advance.
Go to the top of the page
 
+Quote Post
greentea
post May 5 2005, 11:41 AM
Post #5


HR 2
**

Group: Banned
Posts: 26
Joined: 3-May 05
User's local time:
Jul 31 2010, 07:50 PM
Member No.: 7,341



Thank you too, Randy. (IMG:http://www.highrankings.com/forum/style_emoticons/default/smile.gif)
Go to the top of the page
 
+Quote Post

  
Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



This forum is sponsored by High Rankings, a Boston SEO Agency
- Lo-Fi Version Time is now: 31st July 2010 - 06:50 PM