|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Search Engine Optimization Forum SEO is much easier with help from peers and experts! The WebProWorld SEO forum is for the discussion and exploration of various search engine optimization topics. Any non (engine) specific SEO or SEM topics should go here. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
||||
|
Apache Server Specific
Requirements: Apache Server with mod_rewrite enabled The ability to modify server settings using either .htaccess or access to the server configuration files. www vs non-www Add the following code to the .htaccess file in the root folder of your web content, or to the appropriate area of your server configuration, after the RewriteEngine on directive: Code:
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
Add the following code to the .htaccess file in the root folder of your web content, or to the appropriate area of your server configuration, after the RewriteEngine on directive: Code:
RewriteRule ^/index\.(php|html)$ http://www.yourdomain.com/ [R=301, L] RewriteRule ^(.*)/index\.(php|html)$ http://www.yourdomain.com/$1/ [R=301, L] To prevent duplication of content due to the use of a secure connection (https), the content that should be available as secure should be in a seperate folder. Unfortunately, this is generally not possible. For the sake of completeness, however, here is how to do it. Generally, you would put the secure content in a subfolder of the root folder of your web site. For simplicity, you could name this folder "secure". You would then add the following directives to the .htaccess file in the root directory of your server. Code:
<Directory /secure/> Order Deny,Allow Deny from All </Directory> Code:
Alias /favicon.ico /absolute/path/to/favicon.ico Alias /style.css /absolute/path/to/style.css Alias /img/ /absolute/path/to/img/
__________________
The best way to learn anything, is to question everything. Last edited by wige; 01-17-2008 at 03:57 PM. |
|
||||
|
PHP Code
If you do not have the ability to create or modify your server settings, and use PHP to generate your pages, you can accomplish the same thing by adding a code snippet to the beginning of your scripts. The following code must be the first thing in the script, before any output is sent to the browser. Note that this code should work even if there is an internal mod_rewrite or other URL mapping or aliasing in place. PHP Code:
Handling HTTP and HTTPS If you have HTTPS on your server, and do not want all of your content mirrored on both the HTTP and HTTPS versions, you can add the following lines to the top of every script, below the code I lay out above: PHP Code:
PHP Code:
__________________
The best way to learn anything, is to question everything. Last edited by wige; 01-17-2008 at 04:11 PM. |
|
||||
|
Here's a thorough guide to setting up 301 redirects under IIS.
IIS 301 Redirect for SEO - McAnerin International Inc.
__________________
. Printer ink & toner cartridges in Canada | Web Payroll, online HR tools, time & attendance |
|
||||
|
There's a pretty good article here http://www.webconfs.com/how-to-redirect-a-webpage.php
|
|
||||
|
Great idea, wige. Someone give him some more rep points!
Quote:
And Jaan's page has lots of resources for 301 redirects. I found this one most useful: How to Create Redirects. How about making this a Sticky? Cheers, MJ
__________________
M.-J. Taylor SEO Web Design by Cyber Key Search Smart Design® SEO Copywriter & Traveling Vacation Gypsy |
|
||||
|
Some great suggestions and links already, thanks!
Anyone have any ideas on how to accomplish this type of redirect on ASP .net sites? Generally if your site is on a shared Windows host you won't be able to access the IIS control panel, so this would need to be done programatically. I have seen instructions on doing the redirect: Code:
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com/");
%>
__________________
The best way to learn anything, is to question everything. Last edited by wige; 01-17-2008 at 04:12 PM. |
|
||||
|
PERL CGI Method
This is more commonly going to be used with older scripts and shopping cart systems if the server does not support htaccess. The following code should work with most PERL processors. This code must precede any other output to the browser. Code:
if ($ENV{"HTTP_HOST"} != "http://www.yourdomain.com") {
$q = new CGI;
print "Status: 301 Found\nLocation: http://www.yourdomain.com".$ENV{"REQUEST_URI"}."\n\n";
exit();
}
__________________
The best way to learn anything, is to question everything. Last edited by wige; 01-17-2008 at 03:34 PM. |
|
||||
|
This ASP redirect method allows you to pass along querystrings if you need to.
It fires back valid HTTP Status codes with "HTTP/ 1.1 200 OK" *Caveat: To prevent hacking, It's a good idea to parse querystrings for illegal characters. Check your headers: Check Server Headers Tool - HTTP Status Codes Checker Code:
<%@LANGUAGE="VBSCRIPT"%>
<%
'*****************************************
' 301 Redirect for non-www domain entries
'*****************************************
host = Request.ServerVariables("HTTP_HOST")
page = Request.Servervariables("URL")
pageData = Request.ServerVariables("QUERY_STRING")
'allow passing of querystrings to the redirected URL
if pageData <> "" Then
pageData = "?" & pageData
end if
'substitute yoursite.com for your own URL.
if host = "yoursite.com" then
host = "http://www.yoursite.com"
newUrl = host & page & pageData
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", newUrl
Response.End
end if
'*******************
' End 301 Redirect
%>
__________________
. Printer ink & toner cartridges in Canada | Web Payroll, online HR tools, time & attendance |
|
|||
|
Quote:
Code:
ErrorDocument 500 http://www.insuranceshoppers.net/500.html
__________________
Health Insurance Colorado | Read about Shifting the burden of proof - "Argument from ignorance" |
|
|||
|
Very helpful, and I learned something useful. Thank you.
I will mention though that it's considered more forward thinking to redirect www.domain.com into domain.com rather than the other way around since even Tim Berners Lee considers the addition of www to any URL to be "the old web".
__________________
Custom Templates for ZenCart, CubeCart, ModX, Movable Type, Joomla, Tolranet Directory, J-Board and more! Need an Alternative to Ebay? Let's talk! |
|
||||
|
Allow me to add mine here too:
########## Require the www to avoid cannonicalization issues ### RewriteCond %{HTTP_HOST} ^yoursite.com [NC] RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301] ########## Require to add trailing slash if not present to avoid cannonicalization issues ### RewriteCond %{HTTP_HOST} !^www\.yoursite\.com [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/(.*) http://www.yoursite.com/$1 [L,R] ########## Redirect index.html to / ########## RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html?\ HTTP/ RewriteRule ^(.*)index\.html?$ http://www.yoursite.com/$1 [R=301,L] ########## Redirect https to http ### RewriteCond %{SERVER_PORT} ^443$ RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L] If you have https pages indexed because you have done a mistake, you can create an additional robots.txt calling it for example robots-secure.txt disallowing the indexed files and this in your .htaccess file: ########## To get rid of https files and cannonicalization issues ### #RewriteCond %{SERVER_PORT} ^443$ #RewriteRule ^robots.txt$ robots-secure.txt
__________________
"Being an expert isn't telling other people what you know. It's understanding what questions to ask, and flexibly applying your knowledge to the specific situation at hand. Being an expert means providing sensible, highly contextual direction." Jeff Atwood SEO Workers - Search Engine Optimization Consulting Company | SEO Analysis Tool | Webnauts Net SEO |
|
||||
|
Hi wige
After I add: RewriteRule ^/index\.(php|html)$ http://www.yourdomain.com/ [R=301, L] RewriteRule ^(.*)/index\.(php|html)$ http://www.yourdomain.com/$1/ [R=301, L] It gave me Error 500. I have no problem when I use this: RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L] Any idea? Last edited by edhan; 01-18-2008 at 12:22 AM. |
|
|||
|
Hi,
Since i am not a programmer, i cannot add my pinch to this forum which nontheless speaks out to me since i am having a new version of my website under development and rewriting / redirection / duplicate content issues are being considered at the moment. All i can say is THANKS for sharing your knowledge and i look forward to get to a topic where i will be able to bring savy advice (SEO) Nice day to all |
|
||||
|
Quote:
__________________
"Being an expert isn't telling other people what you know. It's understanding what questions to ask, and flexibly applying your knowledge to the specific situation at hand. Being an expert means providing sensible, highly contextual direction." Jeff Atwood SEO Workers - Search Engine Optimization Consulting Company | SEO Analysis Tool | Webnauts Net SEO |
|
|||
|
nice.
|
|
|||
|
Very helpful, and I learned something useful. Thank you.
|
|
||||
|
I am glad people have already found the information useful. To address some of the comments....
edhan, I suspect the issue you are experiencing is arising because of a problem in the .php script itself, possibly because the script in question can't handle the filename not being in the REQUEST_URI. If you post (or PM me with) a URL where I can test it and replicate the issue, I may be able to confirm. The order of mod-rewrite directives vs other directives in your .htaccess file should not have any impact on the functionality. Error 500 though indicates an error in the script itself. Webnauts, I have a question for clarification about one of the snippets you posted, specifically, Code:
########## Require to add trailing slash if not present to avoid cannonicalization issues ###
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.yoursite.com/$1 [L,R]
Please note, when doing redirects, R uses a 302 redirect (at least in Apache 2.0-2.2), using R=301 will force the server to respond with a permanent redirect, which is generally preferable so that search engines properly process the redirect. I'll also add, as DoneInStyle stated above, intellectually, yourdomain.com is preferred over the older, traditional www.yourdomain.com. However, I used www in all my examples because, well, I'm pandering to user expectations. Most servers and hosting companies up to a few years ago forced hosted sites to use www, www was also used to "brand" a company's Internet presence in offline marketing. This has ingrained www into the consciousness of the web-going consumer. It is second nature for users to enter www before a URL when trying to remember an address (as indicated in numerous usability studies, as well as the AOL Personal Information Giveaway - I mean leak) and redirecting a user, even seamlessly, could have the potential of disrupting the user experience, simply by defying the expectations of the user. Also, as most security certificates are issued for the www subdomain, some browsers may issue a warning when users change subdomains when entering or leaving the secure connection. This is all my own opinions, and not really the place to debate which form is better, I just wanted to address the comment and point out that yes, I did use www in all my examples for this reason, and if you prefer the non-www form be aware of this and modify the code accordingly.
__________________
The best way to learn anything, is to question everything. Last edited by wige; 01-18-2008 at 10:54 AM. |
|
||||
|
Quote:
With regards to using www, from my understanding, it does not make a difference to the search engines. And although it may appear to be "old web" it still makes sense with all of the new TLCs coming out, this way, when your url is used in print or any other medium, it is automatically known that it is a website. I know it is hard to believe but there are many people who still dont know the difference between and email address and a website address. |
|
||||
|
Quote:
Thanks! |
|
|||
|
So if i understood correctly, to be able to have just a part of the site be https without touching the .htaccess file then all pages have to be php. Is this correct?
|
|
|||
|
On my interior pages, like www.mysite.com/help.html, my website shows an error if the user leaves off the .html (www.mysite.com/help). Is there something I can add to the .htaccess to fix that problem?
__________________
Health Insurance Colorado | Read about Shifting the burden of proof - "Argument from ignorance" |
|
||||
|
It is possible. There are two situations you may encounter: the trailing slash may be omitted, or the file extension may be omitted. You would need to look at your logs and determine which happens more often and correct for that situation, and let the other situation be resolved through custom error pages.
If you want to add a trailing slash / if no file name is specified (domain.com/file becomes domain.com/file/) use the following: Code:
RedirectMatch 301 ^/([a-zA-Z0-9/]*)$ http://domain.com/$1/ Code:
RedirectMatch 301 ^/([a-zA-Z0-9/]*)$ http://domain.com/$1.html
__________________
The best way to learn anything, is to question everything. |
|
|||
|
Thank you, Wige... although I doubt my Control Panel lets me do that. We host all our clients in GoDaddy. But we've come across something else - a little piece of javascript that you put into the html files that you want to keep as http. Would you mind checking to see that I didn't mess up again? The site is spauno.com. Only the "Reservation" pages and the contact sheets need to be https. What was happening was that when you navigated out of an https page and went to an http page, it would show this last page as also being secure, even if you had previously navigated it in http. This was creating the duplicate content. For some 6 months G wouldn't touch this site not even with a 10 foot pole. I hope this will get my client ranked.
|
|
||||
|
The Javascript you have in use seems to work, however this type of redirection is not generally supported by the search engine spiders. You could run the risk of the https version of the page being indexed or, worse, dropped if the search engines see the Javascript redirection as sneaky/suspicious.
__________________
The best way to learn anything, is to question everything. |
|
|||
|
Thank you so much for your help... and unfortunately you are right about being dropped. Over the weekend G un-indexed all pages except for the php and one html where we forgot to put in the "magic" code. Ouch. Like I said, the site has no htaccess file, goes crazy every time we try to put one in, and the Control Panel does not have an option for singling out pages, or much of an option for controlling anything really. Would you suggest we change everything into php? Or is there something else we can do?
|
|
||||
|
In your case I would recommend contacting your web host to find out what they recommend to get this working. You would get the best results from setting this up through .htaccess, but the hosting company may need to change or enable something to get it to work for you.
__________________
The best way to learn anything, is to question everything. |
|
||||
|
Webmax, Godaddy is notorious for this sort of problem. My best suggestion to you is to simply google "Godaddy Hosting" and then, having had your eyes truly opened, search for a real host!
I'd start your search here: Web Hosting Talk - The largest, most influential web hosting community on the Internet |
|
||||
|
You get what you pay for.
|
|
|||
|
So I just called them and they said that yes, their $43.05 shared hosting supports htaccess files. They checked a sample of the htaccess we had written and said it needed fixing. So the mistake is ours, not theirs... (It's against their policy to rewrite code supplied by the client, otherwise the guy would have fixed it for me.)
For the sake of Wige's compilation of solutions to canonicalization problems, if ever we come up with that file and it works, we'll copy it here. Thanks to all for your help. |
|
|||
|
Hello Wige, it's me again, back from Google hell with total forgiveness of all my sins...
We put this into an htaccess file outside of the secure folder: RewriteEngine On RewriteCond %{SERVER_PORT} !80 RewriteRule ^(.*)$ http://www.spauno.com/$1 [R,L] We put this into another htaccess file inside the secure folder: RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} secure RewriteRule ^(.*)$ https://www.spauno.com/secure/$1 [R,L] You can now navigate back and forth between secure and unsecured content without creating duplicate content and Google has reindexed the pages. So to be able to say that this works for sites in shared hosting, specifically GoDaddy Linux hosting, all we need is Wige's blessing. |
|
||||
|
Looks good to me, and it should work in most Linux setups. The only thing I would change is from
RewriteCond %{REQUEST_URI} secure to RewriteCond %{REQUEST_URI} ^/secure/ That should prevent issues if you have another page on the site that includes the word secure in the filename from triggering an endless loop of redirects.
__________________
The best way to learn anything, is to question everything. |
|
|||
|
Does flash content creates conical issue?
|
|
||||
|
Quote:
Well, I added that option with the trailing slash, since it is technically different than without it. SEO advice: url canonicalization Also many try to get IBLs adding the trailing slash in their URLs like http://www.justanexample.com/, aiming to flow the PageRank only to their homepage. If you probably have noticed, many web directories forbid that already. Besides, if you have such IBLs, do you exclude the possibility that Google or other SE will not see that as a canonical issue?
__________________
"Being an expert isn't telling other people what you know. It's understanding what questions to ask, and flexibly applying your knowledge to the specific situation at hand. Being an expert means providing sensible, highly contextual direction." Jeff Atwood SEO Workers - Search Engine Optimization Consulting Company | SEO Analysis Tool | Webnauts Net SEO |
|
||||
|
Quote:
http://domain.tld/somepage.html Spider sees Protocol: http Hostname: domain.tld Request URI: /somepage.html http://domain.tld/ Spider sees Protocol: http Hostname: domain.tld Request URI: / http://domain.tld Spider sees Protocol: http Hostname: domain.tld Request URI: / (The request URI can NEVER be blank, and MUST ALWAYS start with a /, so if no URI is included in the URL, a slash is used by default.) Even when the spider stores the information about the retrieved page in the index, (think giant relational database) that slash is always added, simply because the field containing the request URI can't be blank. The same happens when storing a list of links - the slash is added if not already present. Specifying a leading slash at the beginning of the Request URI is also expected by the server. If a request reaches your server without that leading slash, the server may simply give a bad request message, or ignore the request, depending on how your server is set up. I have also gotten indications from Google, Yahoo and MSN that their systems always add a leading slash if it is not already present, as does every malbot and spider system I have ever worked with. Even wget, which was the foundation for many spiders, automatically adds the slash. It is simply a default part of the HTTP protocol. Regarding the link you mentioned, I take it you are referring to the following: Quote:
Above all, it is important to remember that to a server, the requests for www.example.com and www.example.com/ both look identical (GET / HOST: www.example.com) so anything you do on the server to redirect from one to the other is pointless anyway.
__________________
The best way to learn anything, is to question everything. Last edited by wige; 05-16-2008 at 10:51 AM. |
|
|||
|
[QUOTE=wige;358772]
If you want to add a trailing slash / if no file name is specified (domain.com/file becomes domain.com/file/) use the following: Code:
RedirectMatch 301 ^/([a-zA-Z0-9/]*)$ http://domain.com/$1/ The simplest use of a webserver is to point it to directory tree and let it serve the files there. Typical conventions are that you do specify a default file extension, for example .html so that domain.com/abc serves domain.com/abc.html. The second common convention is that the domain.com/edf/ shows the list of files available, unless the DirectoryIndex directive (or equivalent for non Apache) is set and the file specified is present, such as domain.com/edf/ actually serves domain/.com/edf/index.html. To clarify when I say serve, I mean it returns thes specified content and not a redirect. This is evident by no change in the URL entry field of the browser. In the context of this thread, this can lead to duplicate content, as for example domain.com/edf/ returns the same content as domain.com/edf/index.html (However, if no one ever links to .../index.html the search engine would never discover the URL) By the way your redirect script would also change domain.com/abc.html into domain.com/abc.html/ K<o> |
|
||||
|
Quote:
RedirectMatch 301 ^/([a-zA-Z0-9/]*)$ http://domain.com/$1/ contains ([a-zA-Z0-9/]) which should only be true if the string does not contain a .. As a result, if a file extension is specified, the user should not be redirected. (The request URI must only contain those characters shown in brackets for the user to be redirected.) This is really intended to counteract a server setting that can allow the server to respond to requests omitting the trailing slash as though the slash was there, although it does also remove a possible error condition that would need to be handled with a 404 by redirecting the user to what is most likely the most desired location.
__________________
The best way to learn anything, is to question everything. |
|
||||
|
Quote:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html?\ HTTP/ RewriteRule ^(.*)index\.html?$ http://www.yoursite.com/$1 [R=301,L] And it works fine! So now I have no problem of getting it displays as: www.mydomain.com for index.php or index.html Thanks Webnauts! |
|
||||
|
WIGE,
great post. Very useful for a client I have. I have gone into the site and used full domain to homepage rather than .index.html. But adding the code into the htaccess file is a great backup. Keep up the good work.
__________________
Looking for a Google Consultant for all your Website Optimisation look no further. Lee Johnson SEO can help. Website Audit - SEO Packages - NEW text to code ratio SEO tool |
|
||||
|
The domain with www and without www are two different domain so there's nothing for you to worry about, but I suggest to own both of the domain and redirect to your chosen main url, to be able to gather all the traffics coming from both domains.
|
|
||||
|
How can someone own a domain with www and not without www, and the way around?
__________________
"Being an expert isn't telling other people what you know. It's understanding what questions to ask, and flexibly applying your knowledge to the specific situation at hand. Being an expert means providing sensible, highly contextual direction." Jeff Atwood SEO Workers - Search Engine Optimization Consulting Company | SEO Analysis Tool | Webnauts Net SEO |
|
||||
|
Quote:
Other commonly used services include File Transfer Protocol (ftp) & Internet Relay Chat (irc). A Domain Name, on the other hand, serves as an identifier of a specific resource that exists within the Internet.
__________________
The Penn State Ticket Man http://www.pennstateticketman.com http://www.happyvalleytickets.com http://www.hounddogtours.com |
|
|||
|
How can I tell if I have Canonicalization issues at pilotjourney.com
|
|
||||
|
Quote:
You want pilotjourney.com to resolve to www.pilotjourney.com. Presently, it doesn't. Essentially, you want the server to check all queries to ensure that they include the "www." portion of the URL. If they don't, you want the server to rewrite the URL to include the "www.". Ya follow? Considering that you're running a .php site, you should be able to find the help you need to set up the rewrite script properly. Good Luck.
__________________
. Printer ink & toner cartridges in Canada | Web Payroll, online HR tools, time & attendance |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Canonicalization | gbb011 | Google Discussion Forum | 10 | 12-06-2007 09:49 AM |
| Prevention of Identity Fraud | TrafficProducer | Internet Security Discussion Forum | 0 | 11-22-2006 07:56 AM |
| Click fraud prevention? | A. Smith | Marketing Strategies Discussion Forum | 0 | 07-26-2006 07:30 PM |
| Online fraud prevention | antifraud | Internet Security Discussion Forum | 0 | 10-19-2005 11:31 AM |
| Spam Prevention Tip | colr | Web Programming Discussion Forum | 19 | 08-25-2004 11:14 AM |
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |