|
|
||||||
|
||||||
| 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 |
|
||||
|
As i think about this question i cant help but think im missing some fundamental point, but here goes.
rewrite or 301 redirect? Some situations need one and some need another but i am a little confused as to which is needed when? For example, I've just started work on a clients site and he has the old www versus non-www thing. Should i use rewrite or redirect? He has links that go to domain dot com and domain dot com/index etc. Should i fix the links and 301 /index to the root domain or rewrite? Most of the standard coding for fixing these problems is rewrite but i always think, why not use redirect? Its a lot simpler? What am i missing? As far as i can see rewrite should be used for unfriendly URLs but why use it for redirects?
__________________
Latest Blog Post: Google Consultant - Should this Job Title be Allowed? - Matt Inertia's SEO Blog - SEOers.org "Carpe diem, seize the day boys, make your lives extraordinary" - Dead Poets Society |
|
|||
|
If you have just a few static redirections, then using simple redirect is the way to go. For all 3xx status codes it doesn't really matter which method you use.
However when you deal with many redirected pages, it is much easier to make some rules using rewrite way, where you can dynamically match a large number of different conditions in a single or few lines. Also, rewrite can make all internal changes non-visible to users, so providing opportunity to e.g. make SEO friendly url's, while maintaining or even changing internal structure (among many other purposes). In your case it is perfectly OK to use simple Redirect 301 Last edited by activeco; 07-28-2008 at 07:17 AM. |
|
||||
|
One of my chief confusions comes from the advice given to people about canonicalization (cant we find an easier word than this?lol). People are often advised to sort out www versus non www problems with rewrite. What would be wrong with doing a 301 redirect:
Code:
redirect 301 domain.com www.domain.com Code:
redirect 301 domain.com/index.htm www.domain.com
__________________
Latest Blog Post: Google Consultant - Should this Job Title be Allowed? - Matt Inertia's SEO Blog - SEOers.org "Carpe diem, seize the day boys, make your lives extraordinary" - Dead Poets Society |
|
||||
|
Yeah, you did cheers. Just clarifying.
__________________
Latest Blog Post: Google Consultant - Should this Job Title be Allowed? - Matt Inertia's SEO Blog - SEOers.org "Carpe diem, seize the day boys, make your lives extraordinary" - Dead Poets Society |
|
|||
|
Quote:
Jean-Luc P.S. I did not see any answer on this elsewhere in this topic. |
|
||||
|
Yeah! Good point! Erm, so those codes dont work. Thats sort of what i was asking. So redirects in this form dont work they have to be formulated relative to absolute.
So rewrite is the only way to solve these canonicalization issues? Sorry for my lack of brain power today. It is explained in this thread http://www.webproworld.com/breakroom...thday-you.html
__________________
Latest Blog Post: Google Consultant - Should this Job Title be Allowed? - Matt Inertia's SEO Blog - SEOers.org "Carpe diem, seize the day boys, make your lives extraordinary" - Dead Poets Society |
|
|||
|
LOL indeed.
Well, my whole point was around the basic question "rewrite or 301 redirect?", which I understood as the general question about preferences in using it, without paying too much attention to your details or validity of your code. And yes, Jan-Luc is correct. The first part of all mod_alias directives (including Redirects) refers to url-path only. |
|
|||
|
But...
Since my statement was firm that using Redirect is possible even in that case, after all it gave me some food for thought about how to do it. Sure enough, I soon came up with the solution. YES, it is possible to redirect www to / or the other way around by using Redirect directive only. So you are witnessing the first outline of that technique ever. It's not the most elegant, but it works. Assuming Apache with virtual domains (I guess a typical server) and access to the server. As most of the www subdomains are aliases for the root domain it is necessary first to check/change it in DNS records. Instead of "www CNAME domain.com." make it "www IN A xxx.xxx.xxx.xxx". The second step is making additional virtual domain with a few lines in httpd.conf (or in include file): Code:
<VirtualHost xxx.xxx.xxx.xxx:80>
ServerName www.example.com
DocumentRoot (the same as root domain)
<Directory />
Redirect 301 / http://example.com/
</Directory>
</VirtualHost>
#Be sure to comment out or delete ServerAlias www directive in / section: ### ServerAlias http://www.example.com Last edited by activeco; 07-28-2008 at 08:56 PM. |
|
||||
|
Quote:
I suggest pay attention to details (internal links) and re-submit a Sitemap. I would suggest using website grader to check "re-direction" issues and suggestions. Use this code: Quote:
__________________
When ever I post something ~ Someone gets offended ~ Poor soul Catalog Solutions | Catalog Rep Agency | Mail Order Catalog Company Last edited by sofomor; 07-29-2008 at 08:18 AM. |
|
||||
|
Quote:
But I would suggest using RedirectMatch 301 /(.*) http://www.domain.tld/$1 instead. This will mimic the mod_rewrite method more effectively, as it will redirect the user to the correct page, rather than the homepage of the www site.
__________________
The best way to learn anything, is to question everything. |
|
|||
|
Quote:
I agree with the RedirectMatch and after a bit of further thinking I can't recall anymore why I suggested changing DNS records. It is not needed at all. I have put the redirect into the <Directory> section just in case of some later additions, which would not be supported in <VirtualHost>, otherwise that too was not needed. So, to summarize the shortest way: #(From www to /) Code:
<VirtualHost xxx.xxx.xxx.xxx:80>
ServerName http://www.example.com
DocumentRoot (the same as non-www domain)
RedirectMatch 301 /(.*)? http://example.com/$1
</VirtualHost>
Last edited by activeco; 07-29-2008 at 12:32 PM. |
|
||||
|
Just to add to activeco's solution a bit more... If you put this virtual host before the virtual host entry for your www domain, it becomes the default for the entire server, basically redirecting every single possible subdomain or any domain name you have pointing to that IP address to your main site.
So, for example, if you have the domain "example.com", and want to use "www.example.com", you would create the following virtual hosts: Code:
# Default catch all - redirects everything not covered in another VirtualHost section <VirtualHost xxx.xxx.xxx.xxx:80> ServerName http://example.com DocumentRoot (the same as non-www domain) RedirectMatch 301 /(.*)? http://www.example.com/$1 </VirtualHost> # Your main domain, the www. subdomain <VirtualHost xxx.xxx.xxx.xxx:80> ServerName http://www.example.com DocumentRoot (the same as non-www domain) # Your directives here </VirtualHost>
__________________
The best way to learn anything, is to question everything. Last edited by wige; 07-29-2008 at 06:08 PM. Reason: Typo |
|
|||
|
this is the code i generally use on the canonicalization issue and to lose the index.html in favour of domain.com/
Code:
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ http://www.domain.com/$1 [R=301,L]
(in simple language please, i didn't write it myself
__________________
Small Business Search Engine Optimisation Fitness Holidays Inmobiliaria Real Estate Ibiza Last edited by kevsta; 07-29-2008 at 02:42 PM. |
|
|||
|
Another Speedo
I knew you meant: RedirectMatch 301 /(.*)? http://www.example.com/$1 |
|
|||
|
Quote:
I agreed with the suggestion, but as I remembered doing something similar in the past with Redirect only, it looked like this case did not need RedirectMatch. Redirect still transfers the whole request to the new destination. So, to save even more typing and processing power "Redirect 301 / http://example.com/" should suffice. Last edited by activeco; 07-29-2008 at 08:30 PM. |
|
||||
|
When you want to fix Canonicalization you have to use 301 redirect. It's neccesary 'cause the search engines handle yoursite.com, www.yoursite.com and yoursite.com/index.html like three different pages and rank them different as well. To correct this you have to do 301 redirects what the search robots understands.
Example: RewriteCond %{HTTP_HOST} ^yoursite\.com [NC] RewriteRule ^(.*) http://www.yoursite.com/$1 [R=301,L] RewriteRule ^/index.php http://www.yoursite.com/ [R=301,L] Cheers, |
|
||||
|
Read the thread dude!
__________________
Latest Blog Post: Google Consultant - Should this Job Title be Allowed? - Matt Inertia's SEO Blog - SEOers.org "Carpe diem, seize the day boys, make your lives extraordinary" - Dead Poets Society |
|
|||
|
Quote:
Could something be missing from this rule set? Thanks. |
|
||||
|
Quote:
Code:
########## Require the www to avoid cannonicalization issues ###
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
########## Redirect index.php to / ##########
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php?\ HTTP/
RewriteRule ^(.*)index\.php?$ http://www.domain.com/$1 [R=301,L]
########## Require to add trailing slash if not present to avoid cannonicalization issues ###
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.domain.com/$1 [L,R]
|
|
|||
|
Quote:
Code:
########## Redirect index.php to / ##########
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php?\ HTTP/
RewriteRule ^(.*)index\.php?$ http://www.domain.com/$1 [R=301,L]
Here's the solution I found yesterday while nosing around the mod rewrite forum. It varies a bit from MuNKyonline's code. Code:
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.php(\?.*)?\ [NC]
RewriteRule ^(.+/)?index\.php$ http://www.domain.com/%1 [R=301,L]
|
|
|||
|
The redirect is working. But now I find that my sitemap generator produces both the old urls and the redirected urls. Google doesn't like this.
For example, I now have all variations of "mysite.com" and "mysite.com/index.php" in my sitemap, where, pre-redirect, I had only the latter. I've been advised to change all my old internal links to reflect the redirect. But this seems to defeat the purpose of the redirect. How should I proceed? |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| using mod rewrite - does it help? | etrader.ie | Search Engine Optimization Forum | 1 | 04-18-2007 07:05 PM |
| Need help with mod-rewrite | ewhitaker | Search Engine Optimization Forum | 9 | 08-11-2006 04:25 AM |
| ReWrite... Should the Old Redirect to the New? | mlevenhagen | Web Programming Discussion Forum | 0 | 06-06-2006 05:13 AM |
| mod rewrite | johnyfav | Web Programming Discussion Forum | 1 | 12-01-2005 06:24 AM |
| MOD rewrite | freehits | Search Engine Optimization Forum | 2 | 02-08-2005 08:16 PM |
|
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 |