CodeIgniter Forums
8 simple 301 redirects not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter Archived (from EllisLab) (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: 8 simple 301 redirects not working (/thread-30942.html)

Pages: 1 2


8 simple 301 redirects not working - El Forum - 06-01-2010

[eluser]charlie spider[/eluser]
I think that too much work and not enough sleep is keeping me from figuring this out! I just need to set up 302 redirects for an 8 page site.

My htaccess file is set up as follows and works perfectly:

Code:
Options Indexes
Options +FollowSymLinks
Options -MultiViews
DirectoryIndex index.php

<IfModule mod_rewrite.c>

  RewriteEngine on
  RewriteBase /

  #RewriteCond %{HTTP_HOST} !^www\.coachhouse\.info$ [NC]
  #RewriteRule ^(.*)$ http://www.coachhouse.info/$1 [R=301,L]

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d

   RewriteRule ^(.*)$ index.php?/$1 [NC,L,QSA]
  
</IfModule>

I initially tried to use regular 301 redirects like:

Code:
<IfModule !mod_alias.c>
redirect 301 /index.htm http://www.coachhouse.info
redirect 301 /features.htm http://www.coachhouse.info/features
redirect 301 /pender.htm http://www.coachhouse.info/pender-island
redirect 301 /location.htm http://www.coachhouse.info/location
redirect 301 /rates.htm http://www.coachhouse.info/rates-and-info
redirect 301 /testimonials.htm http://www.coachhouse.info/guest-comments
redirect 301 /contact.htm http://www.coachhouse.info/contact
redirect 301 /links.htm http://www.coachhouse.info/links
</IfModule>

but those would turn this:
http://www.coachhouse.info/rates.htm

into this:
http://www.coachhouse.info/rates-and-info?/rates.htm

Apparantly you can't mix mod_alias with the mod_rewrite rules for removing index.php from the url.


So then I tried to set up the 301 redirects using rewrite rules like this:

Code:
RewriteRule ^/rates.htm /rates-and-info [R=301]

or this:

Code:
RewriteRule ^/rates(.*) /rates-and-info [R=301]

or this:

Code:
RewriteRule ^/rates(.*) /rates-and-info [R=301,L]

or this:

Code:
RewriteRule ^/rates(.*) /rates-and-info$ [R=301,L]

and every variation/combination of the above I could think of including:

Code:
RewriteRule ^/rates(.*) /rates-and-info [R=301,L,PLEASE GOD PLEASE]



I have tried placing the rules at the end of the:
<IfModule mod_rewrite.c>

and I've tried placing them immediately after
RewriteBase /



but regardless of what I do, a request for http://www.coachhouse.info/rates.htm results in a 404 error.

And I have cleared the cache, tried other browsers, and restarted the browsers between attempts to no avail.

It just doesn't work.


What am I missing or doing wrong ?

Any and all help is greatly appreciated.

Thank you for your time.


8 simple 301 redirects not working - El Forum - 06-01-2010

[eluser]skunkbad[/eluser]
Sleep deprivation makes programming impossible! You always think that you just need a few more minutes to figure something out, but you spend hours. Go to sleep, wake up the next day, and you have your answer in minutes!

Yes, it can be done:

Code:
# This rewritten url is an example of how to redirect any request for a url with query string to the non query string equivalent #
RewriteCond %{THE_REQUEST} ^GET\ /test/whatever\.php.*\ HTTP/ [NC]
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^test/whatever.php(.*)$ http://www.yourdomain.com/test/whatever.php? [NC,R=301]



8 simple 301 redirects not working - El Forum - 06-01-2010

[eluser]charlie spider[/eluser]
Thanks for the help but I think you misinterpreted by post.

I'm not trying to redirect a url with a query string.

I need:

(old url) http://www.coachhouse.info/rates.htm

to redirect to:

(new url) http://www.coachhouse.info/rates-and-info

no query strings. The original site was all static html pages with no PHP anywhere to be found.


8 simple 301 redirects not working - El Forum - 06-01-2010

[eluser]skunkbad[/eluser]
[quote author="charlie spider" date="1275394098"]Thanks for the help but I think you misinterpreted by post.

I'm not trying to redirect a url with a query string.

I need:

(old url) http://www.coachhouse.info/rates.htm

to redirect to:

(new url) http://www.coachhouse.info/rates-and-info

no query strings. The original site was all static html pages with no PHP anywhere to be found.[/quote]

Well, in that case, you are also in luck, because I did something similar to my site a while back, where I removed the file endings. You should be able to work with this:

Code:
# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Block Java Bots
RewriteCond %{HTTP_USER_AGENT} ^Java.*
RewriteRule .* - [F,L]

RewriteCond %{HTTP_HOST} !^skunkbad\.com$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ http://skunkbad.com/$1 [L,R=301]

# Protect application and system files from being viewed
RewriteRule ^(system|application) - [F,L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^portfolio.php [NC]
RewriteCond %{REQUEST_FILENAME} !^development.php [NC]
RewriteCond %{REQUEST_FILENAME} !^about.php [NC]
RewriteCond %{REQUEST_FILENAME} !^faq.php [NC]
RewriteCond %{REQUEST_FILENAME} !^contact.php [NC]
RewriteCond %{REQUEST_FILENAME} !^estimates.php [NC]
RewriteCond %{REQUEST_FILENAME} !^templates.php [NC]
RewriteCond %{REQUEST_FILENAME} !^accessibility.php [NC]
RewriteCond %{REQUEST_FILENAME} !^privacy.php [NC]
RewriteCond %{REQUEST_FILENAME} !^terms.php [NC]
RewriteCond %{REQUEST_FILENAME} !^sitemap.php [NC]

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

RewriteRule /portfolio.php http://skunkbad.com/portfolio [R=301,L]
RewriteRule /development.php http://skunkbad.com/development [R=301,L]
RewriteRule /about.php http://skunkbad.com/about [R=301,L]
RewriteRule /faq.php http://skunkbad.com/faq [R=301,L]
RewriteRule /contact.php http://skunkbad.com/contact [R=301,L]
RewriteRule /estimates.php http://skunkbad.com/estimates [R=301,L]
RewriteRule /templates.php http://skunkbad.com/templates [R=301,L]
RewriteRule /accessibility.php http://skunkbad.com/accessibility [R=301,L]
RewriteRule /privacy.php http://skunkbad.com/privacy [R=301,L]
RewriteRule /terms.php http://skunkbad.com/terms [R=301,L]
RewriteRule /sitemap.php http://skunkbad.com/sitemap [R=301,L]

Options -Indexes

php_value date.timezone "America/Los_Angeles"



8 simple 301 redirects not working - El Forum - 06-01-2010

[eluser]WanWizard[/eluser]
Why make this so very complicated?

Why not use a route to capture the request and re-route it to the proper controller? Or if you want redirection, write a redirect controller, check the URI and redirect from there?


8 simple 301 redirects not working - El Forum - 06-01-2010

[eluser]charlie spider[/eluser]
Using the router would technically work (and would be really easy) but then where would the SEO friendly redirect be???

If you have a page like http://www.somedomain.com/old_page that ranks well on Google, and you update the site and change the url structure to http://www.somedomain.com/new_page, then the ONLY way to maintain your Page Rank when redirecting old incoming links to the new page is to use a 301 redirect.

That's the whole point of a 301 redirect. To tell the search engines "This page has permanently moved, so please transfer all data you have for the old url to this new url".

As well, even if the page didn't have any Page Rank before, Google frowns upon what they refer to as "URL manipulation", which is basically any kind of redirect that isn't a 301 redirect. Since they base Page Rank partially on the keywords contained within a url, they don't like it when the url changes and they are not notified why. No one knows for sure but some say that Google penalizes sites for URL manipulation.

To see this from their perspective and imagine this in it's worst form, pretend you do a search for "best php framework", and find a site called http://www.best-php-framework.com but when you click on the link, the site uses the CI router, or a php script, or whatever other hidden method and redirects you to http://www.buy-v-i-a-g-r-a-online.com.

That's an extreme example, but it's basically the same thing as me using the CI router, or a script, or whatever other hidden method to redirect http://www.coachhouse.info/rates.htm to http://www.coachhouse.info/rates-and-info.

But more than anything, I need to maintain any existing Page Rank. If you are redoing sites for people and NOT using 301 redirects for their old links, then you are a bad developer. Flat out. What's the point of having a great new site that plummets on Google immediately after launch? For some (very few) clients, Google doesn't matter, but for most, their Google Page Rank is important if not everything. I know of a web design company in Vancouver that got sued because the new website they built for a business caused their Google traffic to cut in half.

So it has to be a 301 redirect of some sort.


8 simple 301 redirects not working - El Forum - 06-01-2010

[eluser]Buso[/eluser]
[quote author="charlie spider" date="1275434462"]Since they base Page Rank partially on the keywords contained within a url, they don't like it when the url changes and they are not notified why. No one knows for sure but some say that Google penalizes sites for URL manipulation.[/quote]
Page Rank, AFAIK, is based on incoming links only.

Also, don't trust too much on 301. Google will eventually (if done right) accept the redirection. But some other sites which a lot of other sites need to live (like social media sites, eg: stumbleupon), don't. They will throw things like 'site is not available', no matter what.


8 simple 301 redirects not working - El Forum - 06-01-2010

[eluser]skunkbad[/eluser]
Charlie, you said you had 8 pages, so my second example should work perfectly for you, and it does provide the 301.


8 simple 301 redirects not working - El Forum - 06-01-2010

[eluser]WanWizard[/eluser]
@charlie spider: as I mentioned, when you use the router solution you will lose the 301. So if that's what you're after, the router isn't a good idea.

Still the redirect controller is a valid option. What is the difference between a 301 issued by a redirect and a 301 issued by a CI controller? Apart from the extra overhead because an apache/php/ci thread has to be started?
This is already becoming complicated (with 8 redirects), what if you have 10 times more? Who will be able to maintain the rewrite rules? In a controller, you can use the power of PHP to determine your new URI's...


8 simple 301 redirects not working - El Forum - 06-01-2010

[eluser]charlie spider[/eluser]
Quote:Page Rank, AFAIK, is based on incoming links only.
75-80% is based on incoming links (although nobody but Google knows the exact number) the other 20-25% is what's reffered to by some as On-Site SEO and is determind by the presence of keywords in things like:
- the domain name
- the rest of the URL
- meta tag Page Title
- H1 headings
- plus more like inter-page link text, blah, blah, blah



@skunkbad

I just got a chance to experiment with your method. No dice so far.

This is what I have now:

Code:
Options Indexes
Options +FollowSymLinks
Options -MultiViews
DirectoryIndex index.php

<IfModule mod_rewrite.c>

  RewriteEngine on
  RewriteBase /

  #RewriteCond %{HTTP_HOST} !^www\.coachhouse\.info$ [NC]
  #RewriteRule ^(.*)$ http://www.coachhouse.info/$1 [R=301,L]

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !^/index.htm [NC]
   RewriteCond %{REQUEST_FILENAME} !^/features.htm [NC]
   RewriteCond %{REQUEST_FILENAME} !^/pender.htm [NC]
   RewriteCond %{REQUEST_FILENAME} !^/location.htm [NC]
   RewriteCond %{REQUEST_FILENAME} !^/rates.htm [NC]
   RewriteCond %{REQUEST_FILENAME} !^/testimonials.htm [NC]
   RewriteCond %{REQUEST_FILENAME} !^/contact.htm [NC]
   RewriteCond %{REQUEST_FILENAME} !^/links.htm [NC]

   RewriteRule ^(.*)$ index.php?/$1 [NC,L,QSA]
  
   RewriteRule ^/index.htm http://www.coachhouse.info/ [R=301,L]
   RewriteRule ^/features.htm http://www.coachhouse.info/features [R=301,L]
   RewriteRule ^/pender.htm http://www.coachhouse.info/pender-island [R=301,L]
   RewriteRule ^/location.htm http://www.coachhouse.info/location [R=301,L]
   RewriteRule ^/rates.htm http://www.coachhouse.info/rates-and-info [R=301,L]
   RewriteRule ^/testimonials.htm http://www.coachhouse.info/guest-comments [R=301,L]
   RewriteRule ^/contact.htm http://www.coachhouse.info/contact [R=301,L]
   RewriteRule ^/links.htm http://www.coachhouse.info/links [R=301,L]

</IfModule>

Still throwing 404's