Are you a Google Analytics enthusiast?
More SEO Content
Mod_redirect Or Mod_rewrite?
Posted 03 May 2005 - 10:40 AM
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. :-)
Posted 03 May 2005 - 04:06 PM
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:
Redirect 301 /page.htm http://domain.com/other.htm
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!
Posted 03 May 2005 - 06:58 PM
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.
Posted 05 May 2005 - 11:39 AM
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?
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
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 220.127.116.11 and newdomain.com's IP is 18.104.22.168. 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.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users