Redirecting the Homepage

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
pgoneill

Redirecting the Homepage

Post by pgoneill »

I noticed on a site I'm developing that:

www.domain.com and www.domain.com/home/

...will go to the same location.  If a content editor creates a "CMSMS Link" to the content item "home" it'll go to that second URL.  This isn't a huge deal, but for SEO purposes, it can't hurt to redirect "/home/" to "/".

So, I added the following to my .htaccess file:

Code: Select all

Redirect 301 /home/ http://www.domain.com
But that just sent me to http://www.domain.com/?page=home/

Well, the solution was to create an empty, physical directory called "home" in the site root.

Now, CMSMS still creates links like www.domain.com/home/, but that will automatically redirect to www.domain.com.

http://www.domain.com/?page=home/ still works, but CMSMS shouldn't generate links to it and it shouldn't appear anywhere for bots to pick up.
Pierre M.

Re: Redirecting the Homepage

Post by Pierre M. »

Hello,
pgoneill wrote: ...So, I added the following to my .htaccess file:

Code: Select all

Redirect 301 /home/ http://www.domain.com
But that just sent me to http://www.domain.com/?page=home/
As the order of the lines in the .htaccess matters, this Redirect is inactive if you have put it under the /?page= rewrite.

I agree with you on the / and /home "double home bug". May be you can rename/delete the alias of the homepage so there is only / ? But I prefer your Redirect solution.

Pierre M.
pgoneill

Re: Redirecting the Homepage

Post by pgoneill »

Well, I tested several different variations and placements within the .htaccess file and got the same result each time.

Using this, currently:

Code: Select all

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

Redirect 301 /home/ http://www.domain.com
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

Re: Redirecting the Homepage

Post by tsw »

Its not that easy to make default page links different from others..

redirect sounds overkill to me

one idea is to change your default page alias to index and set prettyurls to use .html end, this solution shouldnt affect SEO as it would be domain.tld/ and domain.tld/index.html

We'll continue to think about this :)
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

Re: Redirecting the Homepage

Post by tsw »

ok, I thought of this some more and you can try this, its not fully tested but should work (please tell if it works and it will be added in 1.1)

Code: Select all

Index: lib/classes/class.content.inc.php
===================================================================
--- lib/classes/class.content.inc.php   (revision 3913)
+++ lib/classes/class.content.inc.php   (working copy)
@@ -1276,6 +1276,12 @@
        $config = &$gCms->GetConfig();
        $url = "";
        $alias = ($this->mAlias != ''?$this->mAlias:$this->mId);
+
+        if($this->mDefaultContent) {
+         $url =  $config['root_url']. '/';
+         return $url;
+        }
+
        if ($config["assume_mod_rewrite"] && $rewrite == true)
        {
            if ($config['use_hierarchy'] == true)
Post Reply

Return to “Tips and Tricks”