Welcome to WebmasterWorld Guest from 54.196.2.131

Forum Moderators: Robert Charlton & goodroi

Message Too Old, No Replies

Merging www.example.com/ and www.example.com/index.htm

It would be helpfull to a few of us if this where added to sitemaps too

     
10:36 pm on Aug 7, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:June 15, 2006
posts:500
votes: 0


Hi Guys

I am unable to code internal home links as www.example.com/
because my html editor always adds the filename to its inbuit navigation links,

I like the software, so i am not keen on changing it, an cos thelinks look nicer than anything i can do, i don't wanna hand code links

In any case the damage is already done, google has separately indexed both so I really need to redirect

QUESTION

Can anyone give me a code snippet to recognise urls typed into the browser address bar? that way, I can then do a permanet redirect

ASP.net/vb.net is what I know, but I think i could adapt c# code or asp classic

Cheers

P.S. Perhaps the SiteMaps could also handle this issue someday :)

11:50 pm on Aug 7, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


One of these in your .htaccess file will do it:

RewriteEngine on
# For index.html and index.htm only, without parameters, and only in the root:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html?\ HTTP/
RewriteRule ^index\.html?$ http://www.example.com/$1 [R=301,L]

OR

RewriteEngine on 
# For index.html and index.htm in the root or in any folder, with or without parameters, preserving folder:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.html?(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.html?$ http://www.example.com/$1 [R=301,L]

Add

[NC]
to both lines if you need it to also redirect for any case of INDEX filename.

Beware that posting in the forum modifies the ¦ pipe ¦ characters so you will need to change those back.

[edited by: tedster at 4:02 pm (utc) on Oct. 28, 2008]
[edit reason] improve code efficiency [/edit]

12:00 am on Aug 8, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:June 15, 2006
posts:500
votes: 0


hi g1smd

I am on a shared MS IIS server so, htaccess is not for me,

I've been trying asp.net code using servervariables("Path_info") but it doesn't work so far

infact i think i've got my server in an unbreakeable loop right now!

12:14 am on Aug 8, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:June 15, 2006
posts:500
votes: 0


iam testing for path_info = "", is it possible that ms IIS has already substitued the default/index homepage file even before the

"Application_BeginRequest" event?

I use default.aspx, an I canna remember what my hosts default is called ,,,

2:17 am on Aug 8, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:June 15, 2006
posts:500
votes: 0


Ok, i seem to have found a work around

Cheers

11:07 pm on Aug 8, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


How about posting it here?

The question gets asked often enough that you won't be the only one looking for that solution...

1:14 am on Aug 9, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:June 15, 2006
posts:500
votes: 0


Okay, this solution might not work for every MS IIS setup but here goes

1, servervariables("Path_info") is the wrong one, I needed to use
serervariables("URL") to get the "/index.htm" part off the
url "http://www.example.com/index.htm"

2, Finally getting and displaying on a webpage the above from no1
revealed that if "http://www.example.com/" is entered into the
address bar ,MS IIS automatically attaches its number one choice
website homepage to the url before running the asp engine.
This implies that the
a, the ASP code always sees a full url
"http://www.example.com/index.htm"

b, the visiting user or search engine only see the incomplete url
if that is what the link they clicked on shows
"http://www.example.com/"
this is because the addition off the number one homepage is
entirely serverside, i believe anyway

Work around:
I have both index.asp and default.aspx in the webroot, now I believe the homepage priority order is
index.htm
index.asp
index.aspx
default.htm
default.asp
default.aspx

so i simply put the classic asp 301 redirect code in the blank index.asp file redirecting to the

default.aspx file which is actually the real homepage

Well, it actually works as I want, plus my other non-www to www code in the global asax is not affected

I dunno yet if it'll resolve my google worries but the signs are promising, i seem to be getting a new page indexed everyday, but this is only over 2 days, so ,,, who knows

If this is total s%!t kindly say so an we can find the right answer

cheers

2:47 am on Aug 9, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:May 24, 2005
posts:554
votes: 0


Would I be best advised to do this with my relative to document site?

And how best would I convert ..index.php to mysite.com/

9:47 am on Aug 9, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:June 15, 2006
posts:500
votes: 0


Hi lobo,

That solution was For Microsoft IIs, for PHP/unix type systems,

see g1smd's solution above, or perhaps send him/her a sticky

11:13 am on Aug 9, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


For
index.php
, you could simply replace "
html?
" in my above example with "
php
" in four places:

RewriteEngine on
# For index.php, without parameters, only in the root:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/$1 [R=301,L]

OR

RewriteEngine on 
# For index.php, in the root or in any folder, with or without parameters, preserving folder:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.php$ http://www.example.com/$1 [R=301,L]

OR you could make it multi-functional by redirecting for several different names:

RewriteEngine on 
# For index.html and .htm .shtml .php .php4 .php5 in the root or in any folder
# Works for requests with or without parameters, and preserves original folders:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(s?html?¦php[45]?)(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(s?html?¦php[45]?)$ http://www.example.com/$1 [R=301,L]

Add

[NC]
to both lines if you need it to also redirect for any case of INDEX filename.

Beware that posting in the forum modifies the ¦ pipe ¦ characters so you will need to change those back.

[edited by: tedster at 2:37 am (utc) on Mar. 5, 2009]
[edit reason] improve code efficiency [/edit]