Forum Moderators: phranque

Message Too Old, No Replies

Consistent Home Page URL

         

AsimJ

8:42 pm on Mar 12, 2006 (gmt 0)

10+ Year Member



I am trying to standardize on a single home page URL. At the moment all the following work:

[my-site.com...]
[my-site.com...]
[my-site.com...]
[my-site.com...]
[my-site.com...]
[my-site.com...]

Can I place directives in the Apache httpd.conf virtual host configuration or .htaccess file?

Many thanks in advance for any advice.

jeremy goodrich

7:36 pm on Mar 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can place the modifications in the .htaccess file, though if you're site gets to scale, it might take a performance hit if many users are requesting all the variants and the redirects only live in the .htaccess file. If lots of users will be using each flavor of URL, even over time after you've consolidated the URLs, then best bet is to compile it into the httpd.conf file.

webdoctor

1:20 pm on Mar 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can I place directives in the Apache httpd.conf virtual host configuration or .htaccess file?

Be very careful how you do this - or you may have duplicate content problems.

jdMorgan

8:17 pm on Mar 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



An important question is, what URL do you want to use for the single 'consistent' home page?

Jim

AsimJ

11:22 am on Mar 15, 2006 (gmt 0)

10+ Year Member



Thanks for all the advice.

I want to use "http://www.my-site.com/home.php" as my consistent home page URL.

Exactly what directives should I place in the httpd.conf Apache configuration file?

webdoctor

11:29 am on Mar 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want to use "http://www.example.com/home.php" as my consistent home page URL.

WHY?

1. If you ever migrate your site to a different technology (e.g. ASP.Net), you'll have to change your homepage URI.

2. If you get inbound links, it's unlikely that they will all reference http://www.example.com/home.php - most people would assume that http://www.example.com/ is the home page of a site.

Read the W3C's page Cool URIs don't change [w3.org]

Perhaps you should consider using http://www.example.com/ - it's the "standard" way to do this, after all...

AsimJ

9:50 am on Mar 16, 2006 (gmt 0)

10+ Year Member



Webdoctor you make a excellent point! The consistent URL should be "http://www.my-site.co.uk/"

Coming back to the httpd.conf file directives, how do I make Apache enforce this consistent URL?

Our httpd.conf file currently has the following directives for this domain:


<virtualhost www.my-site.co.uk>
ScriptAlias /cgi-bin/ /www/#*$!/cgi-bin/
ScriptAlias /cgi-#*$!1/ /www/#*$!1/cgi-bin/
User xxx
Group xxx
ServerAdmin webmaster@my-site.co.uk
ServerName www.my-site.co.uk
ErrorDocument 404 /missing.html
DocumentRoot /www/xxx1
DirectoryIndex home.php
LogFormat "%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\""
TransferLog logs/xxx-access-log
</virtualhost>

webdoctor

11:13 am on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



how do I make Apache enforce this consistent URL

Note: please use www.example.com (not "my-site" or varations of it) when discussing domains - it's there for this purpose.

Do you have mod_rewrite on your server?

AsimJ

11:32 am on Mar 16, 2006 (gmt 0)

10+ Year Member



Yes, we have mod_rewite enabled.

webdoctor

11:37 am on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is one part of the solution:

Set up a second virtualhost for the servername example.com, set it to serve content from a DIFFERENT directory to www.example.com, and in this directory put a .htaccess file like this:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]

If a visitor requests http://example.com/content.html it triggers mod_rewrite to issue a 301 Moved Permanently redirect to http://www.example.com/content.html

jdMorgan

5:41 pm on Mar 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Redirect non-standard domain and/or home page client requests to consistent URL:

RewriteCond %{HTTP_HOST} ^my_site\.com [NC,OR]
RewrireCond %{THE_REQUEST} ^[A-Z]{3,9}\ /home\.php [NC]
RewriteRule .* http://www.my-site.com/ [R=301,L]

Jim