Forum Moderators: phranque
>>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]
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.
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.
<?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.
<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]
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.
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.
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.
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.
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?
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.
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.
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.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R,L]
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)
<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]
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.