Forum Moderators: Robert Charlton & goodroi
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 :)
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]
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
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]