Forum Moderators: phranque

Message Too Old, No Replies

Host says no 301 redirect in htaccess

new site, new host, no 301's

         

texasville

6:46 pm on Oct 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just completed a site for a friend that needs this site to drum up some business for her interior decorating. I told her which host to go with. Unfortunately she got confused and has already paid for a year at another host.
Tried to make the best of it but kind of froze when I see I have no access to the .htaccess folder. Moved on. Uploaded the site but before I start a link program and try to get it indexed, decide to write the host and ask for them to do the 301 redirect non-www to www so as to head off problems with google.
Just got this letter back-

>>Dear Sir,

<paraphrased>

Due to technical limitations redirects using .htaccess are not possible. Redirects are possible in php.

<<

I wasn't expecting that one. This site is completely html. She can't afford another hosting fee. And I am doing this whole site as a friend. (read-free)What to do, what to do.

[edited by: trillianjedi at 9:46 am (utc) on Oct. 29, 2005]
[edit reason] Please see TOS re email quotes - paraphrasing [/edit]

Longhaired Genius

7:21 pm on Oct 18, 2005 (gmt 0)

10+ Year Member



That's right. Because it's a virtual domain, all the files for www.mysite.com are actually put into www.mysite.com/htdocs and the server takes care of the necessary redirects.

texasville

7:31 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well..I just tried the other code and I am back to server error 500..no site.

2by4

9:25 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your host already told you they don't support mod_rewrite, I doubt they lied to you.

That's pretty common among junk hosters by the way.

Assuming you are using a real FTP client, like filezilla, it has an internal setting that says 'view hidden files', check that, that's why you couldn't see the .htaccess file.

If you made any typo at all, or if you failed to add a line break, that's hitting the enter key, after the last line of .htaccess code, you will get a 500 error.

My guess is you didn't add the linebreak after the last line.

If you don't have mod_rewrite enabled on apache, then you can't do mod_rewrite, but it should just be ignored. We are assuming by the way that you are on apache server, not IIS/microsoft, which almost never supports rewrite on shared hosting.

There may be worse product out there to use to generate htaccess and any other web file than frontpage, but I'm not aware of it, try a real code editor, there's lots of free ones out there, crimson editor is good, others can recommend other ones.

I read this stuff about renaming .htaccess all the time, here's an alert: use a real text editor and real ftp client and you can make it without any problems. You can run .htaccess on windows/apache, windows has zero problems with .htaccess, this is a lingering myth that comes from using junk programs like frontpage, it has nothing to do with windows.

The .htaccess file can go anywhere, but normally you'd put it the same place you put your index.html file, or whatever you called it. That varies web server to webserver, it's the site root folder, the folder where your site physically resides that is.

texasville

10:14 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



yes. I figured once he said it was virtual host and so forth it wouldn't work to do because mod-rewrite wouldn't be on. I have already emailed the host and asked them to either fix it or refund and we would move. Thanks for every one's help. It's a great community.

texasville

3:00 pm on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just wanted to update how this worked out and see if ya'll see any problem with it. Remember this is a straight html site.
After I asked for a refund and said we were moving they came up with a php script they installed. I had to rename my index file to index2.html and now I have my 301 redirect. I ran a header check and it shows 301 on non-www and a 200 on the 200 version. So, looks like everything turned out alright other than the original aggravation. Thanks for everyones help. I now understand the apache and htaccess. I have never had to deal with it before as always been on microsoft servers.

2by4

6:42 pm on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



that's not a solution, all they did was add a 301 redirect to the index page, not to any other page on the site.

I would stop wasting my time with these guys if I were you.

g1smd

2:12 pm on Oct 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Their new script is hindering, not helping. The redirection you require is for all non-www pages, not just for the index page. Get rid of it.

If you stay with this host, there is one thing you can do to help yourself greatly - add this to every page of the site in the <head> section:
<base href="http://www.domain.com/">. This will almost fix the problem. It is vital that the code goes on every page, especially the main index page.

Another thing you can do is to add some PHP code to the very beginning of every one of your HTML pages (the code goes before the <html> tag). The PHP code does the redirect, and the hosts will therefore need to allow you to parse .html files as containing PHP scripts.

They do this by adding this to your configuration file:
AddType application/x-httpd-php .php .html
but again, they may say that they do not allow this to happen.

The code you put on each page is related to this:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location:
http://www.newdomain.com/newdir/newpage.htm");
exit();
?>

but the script will first need to "test" the URL that was asked for and only run the code if the www is missing. Additionally it will need to extract both the folder and file path from the original request, and then add it back to the redirected URL.

I am sure that some PHP wizard could knock that up in under 5 minutes.

g1smd

2:36 pm on Oct 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This is the "logic" of what you need:

<?php

$page-url == [HTTP_SELF]
$the-domain == (strip off all the stuff after the domain from $page-url and throw it away)
$page-path == (strip off all the stuff after the domain from $page-url and keep it)
if $the-domain does-not-include "www" then do the stuff below:

header("HTTP/1.1 301 Moved Permanently");
header("Location:
http://www.domain.com/ + $page-path +");
exit();

?>

I have no idea about the actual code to do that. I rarely dabble with scripting.

texasville

3:19 pm on Oct 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, because of ww being down I hadn't been back to this post.
I appreciate the help. I feel like a dumba** for not realizing the index page was the only one being redirected.
This is their reply to me:

<paraphrased>

Dear Sir,

Using mod-rewrite for URL forwarding. We've built a php script for you to use instead.

</paraphrased>

How did I get mixed up with such a mess?
I think it is just time to move the site. I would have to do ridiculous extra coding to keep adding pages and not sure if this coding would cause se's to misinterpret.
Wish I knew what the heck real time forwarding is and why they can't do it on my site.

[edited by: trillianjedi at 9:48 am (utc) on Oct. 29, 2005]
[edit reason] Paraphrasing email, please see TOS [/edit]

g1smd

3:27 pm on Oct 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you can get the <base> tag placed on every page, that will protect you quite a bit from having the wrong version indexed. The redirect is a better insurance, but in most cases the <base> tag alone will suffice.

If you can get the host to allow .html files to be parsed as PHP pages, and add the script I have outlined above to every page of the site then that will totally fix the problem. In fact you could put the script in a small file in, say, /includes/redirect.script.php and then just have an include instruction on every page of your site to include that script within. You still need to allow .html files to be parsed as PHP.

It matters not where the redirect comes from: the httpd.conf file, the .htaccess file, or from a PHP or CFM or ASP script. To the user-agents requesting access, all that is important is that they are fed a status code of "301" and the URL to be redirected to.

texasville

3:40 pm on Oct 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks g1, I may give that a try.

Romeo

4:18 pm on Oct 28, 2005 (gmt 0)

10+ Year Member



... and I doubt that a hoster who does not allow simple redirects will allow php parsing in html files.

Perhaps you may reconsider 2by4's early advice in msg 2: move on. You already have spent far more efforts than the $3 per month are worth it.

Sorry to sound that negative, but it may help you in the long run.

Regards,
R.

ergophobe

5:07 pm on Oct 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you wanted to use g1smd's method, you would do something like this

if ($_SERVER['HTTP_HOST'] == "example.com")
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com" . $_SERVER['REQUEST_URI']);
exit();
}

That should send the right header before redirecting and hopefully sending a 200 as well on the final page. I haven't tried it though.

g1smd

5:33 pm on Oct 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Heh, that looks good and somewhat more simple than I had originally imagined.

Get that code on every page, inside a set of <?php ..... ?> tags, and above the DOCTYPE and <html> tags; or better yet get that code onto a separate page that you include above the DOCTYPE and <html> tags - so that if you no longer require the redirect in the future, you just need to amend the single included file, not every HTML page of the site.

You still need to ask the host to set up .html files to be allowed to be parsed as PHP files. If they can't do that, then move host (make sure it uses Apache). That redirect and include stuff is in Chapter 1 of "Hosting 101", but far too many hosters have no clue, and Windows hosting severely restricts your choice.

ergophobe

7:28 pm on Oct 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I know they won't allow rewrites, but if you can set php directives in your .htaccess, you could set that script as your auto-prepend file and thus auto-include it in every page, without touching your pages at all.

g1smd

8:08 pm on Oct 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Nice! I had never heard of Auto-prepend.

Now that is useful.

peter andreas

6:56 am on Oct 29, 2005 (gmt 0)

10+ Year Member



I have exactly the same issue, tried to add the .htaccess file (which I discovered about from WebmasterWorld a week or so ago) it didn't work so contacted our host and they said they didn't support it and suggsted a perl code. The also said what was the issue anyway as both www and non www worked? I wonder if its the same host they claim to be one of the biggest in the US. Our pr is split, 3 on non www and 5 on www...

I'm going to wait before I dabble in case I muck it up and from what I gather on the massive jagger thread they may fix this canonical issue? Wishful thinking?

g1smd

5:55 pm on Oct 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What the jagger3 update will correct, if I have understood things right, is the many non-www listings that still show up in the SERPs many months after the redirect to www was put in place.

GoogleGuy has already urged, many times, that you should add the 301 redirect to help fix this issue. Add the redirect code. Verify the redirect action, and the 301 status code. Get on with whatever you were doing before.

Dayo_UK

5:59 pm on Oct 29, 2005 (gmt 0)



g1smd

It will be disappointing if that is all they fix.

What about all the webmasters who dont read Webmasterworld, Matts Blog etc, and have never heard of the 301 fix - each update more and more sites get hit by the problem. One (well me) would hope that a new way of handling the situation is forthcoming.

texasville

11:15 pm on Oct 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I do have3 a question. How do you set up an auto prepend file? What script would I need? I can't even get a hold of these guys right now. They got washed out by wilma and supposedly I am running off servers I don't know where. We were down for a day and a half.

g1smd

11:26 pm on Oct 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Google for Apache Auto Prepend htaccess (find out if it is something you can do, or whether the host needs to set that up), and then you'll also need the script above to be loaded on your server (you can do that).

You need the Apache Auto Prepend function, one that goes in the .htaccess file I think, not the PHP one for adding to other scripts.

g1smd

11:35 pm on Oct 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Third Google result says (with rewording by me to fit your situation):

>> Save your redirect script file as redirect301.php

>> In your .htaccess, add the following line:
php_value auto_prepend_file /redirect301.php

That's it.

outrun

12:00 am on Nov 1, 2005 (gmt 0)

10+ Year Member



I had the 500 internal server problem as well when I tried a 301 redirect with htaccess I just added "Options +FollowSymlinks" and it went worked, so the .htaccess file would look like so:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R,L]

g1smd

12:10 am on Nov 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Nearly, you need R=301 instead of just R to be sure.

I think R on its own is a 302 redirect. You don't want that.

Use a program like WebBug to check the server reponse codes.

.

In the example above, there should be a space after the {HTTP_HOST} and before the !^www.example.com [NC]
(the forum software here removes it)

texasville

3:52 pm on Nov 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



G1-you are a virtual fountain of knowledge.
However, I just got this reply(finally) from support:

<paraphrase -- direct requests "without www" will be redirected to "with www"> [tedster]

I went to check if it is in effect yet and ...the site is down. I understand their problems with hurricane wilma so I'll give them a day...and then I must move. But I have to hand it to them-they became aware of a problem from a customer and moved on it to satisfy not only me but all their customers.
Of course, got to know if it works first.
Thanks so much for the help and this thread will undoubtedly help others. But if is a problem, I am just going to move.
Texasville

[edited by: tedster at 4:38 am (utc) on Nov. 2, 2005]

texasville

6:39 pm on Nov 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well site is back up and I checked and they 302'd it not 301- but got to give them an e for effort.

g1smd

8:07 pm on Nov 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oh dear; but unfortunately most hosts are totally clueless when it comes to search engine issues.

You most definately do NOT want a 302 redirect. That was what got MSN their Toolbar PR of 2 last week.

>> G1-you are a virtual fountain of knowledge.

Nah. Just know where to look for the answer: Google search or ODP category.

texasville

7:52 pm on Nov 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey G1- They got it all fixed after my email yesterday and now it all 301's. Thanks again!

g1smd

8:25 pm on Nov 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just making sure that if you ask for domain.com/page.html then you get redirected to www.domain.com/page.html, and likewise for any page or folder on the site...
This 59 message thread spans 2 pages: 59