Forum Moderators: phranque

Message Too Old, No Replies

htaccess Redirect 500 error

Not working to sub-domain

         

Angonasec

2:56 am on Dec 25, 2003 (gmt 0)



In my domain root I've an .htaccess file using the following format to redirect internal (and external) calls for files as follows:

Redirect permanent /old.file.name.htm
[subdomain.my-domain.com...]

This format works fine for all files, *except those in my sub domain*. Clicking on a full url link within my site to the subdomain gives a blank white screen for about two minutes, (which shows in the access file as a 301) then the internal server error 500 shows in the browser and the error log, with the entry:
"URL to redirect to is missing"

When you call the file directly by typing into the browser, it displays fine.

So why isn't the redirect code working...

What am I doing wrong?

Ta!

jdMorgan

4:58 am on Dec 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Angonasec,

If you have implemented your subdomain as a subdirectory of your main domain, then the code you posted will "loop forever" and eventually time out.

If you have access to mod_rewrite, this can be avoided by testing for the presence of the subdomain in the requested URL and making the redirect occur only once - conditionally.

Unfortunately, the Redirect and RedirectPermanent directives do not support conditional redirection.

Jim

Angonasec

4:49 am on Dec 26, 2003 (gmt 0)



Thank you JdM, that will be the reason.

I'm hosted at FQ, and that is indeed how they set up sub domains when you buy them.

Now, I'll have to dive into those Mod_Rewrite examples here, and see if I can get it to work.

Ta!

jdMorgan

5:03 am on Dec 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Angonasec,

You could start here [webmasterworld.com] with a recent thread on subdomain->subdirectory redirects.

Jim

Angonasec

10:59 am on Dec 26, 2003 (gmt 0)


Okay, here's my honest attempt, based on studying threads here and a lot of head scratching:

There are only six files that I need to redirect, so I don't mind coding for each individually to keep it simple.

My host has Apache and mod-rewrite, Sym Linx enabled, so will this in my root .htaccess work safely?

Basically, all I want to do is redirect both internal and external calls for certain files in my main directory to the same file (but renamed) in a sub domain of the same domain.
Note: My-domain-has-hyphens

Untested attempt:

RewriteEngine on
RewriteRule ^old\.file\.name1\.htm$ http://subdomain.my-domain.com/new.file.name1.htm [R=301,L]
RewriteRule ^old\.file\.name2\.htm$ http://subdomain.my-domain.com/new.file.name2.htm [R=301,L]
RewriteRule ^old\.file\.name3\.htm$ http://subdomain.my-domain.com/new.file.name3.htm [R=301,L]

I think this would work for external calls coming with or without www, or do I need to add the anti-looping line:

RewriteCond %{HTTP_HOST}!^www\. [NC]

I appreciate your kindness and advice.

Colin

PS. I'll certainly study the thread you mention JdM

Angonasec

12:36 pm on Dec 27, 2003 (gmt 0)



Well, I tried my own suggestion, and it didn't work, or do anything!

I also looked at the thread you mentioned Jim, but it doesn't approach my need.

To clarify:

I'm on a virtual account, that has an existing genuine subdomain (A DS-IRM fixed up by my host for a mere $25!).

So, for example: [yellow.colours.com...] actually points to: [colours.com...]

The yellow subdomain appears as a folder in my main directory.

I mention this in case it affects the mod rewrite code I'm trying to create.

All I'd like to do is move six files permanently from my main directory into the subdomain and have all calls (both from links within my site and outside it) redirected to them in the subdomain.

A common enough requirement, I'd have thought, surely mod_rewrite can do that? But I've searched for days, both the Apache docs / guides, and this forum, and I can't find a single example of it.

To add a layer of complexity, I'd also like to rename each file from their current y.2.htm format to the more SE relevant yellow.pale.htm format. But this is of 2ry importance, I can always use Redirect permanent to rename the files using an .htaccess file within the subdomain.

So, I need mod rewrite code for my root access .htaccess file to redirect calls for six files in my main directory to an existing subdomain, using the same file name.

And in the subdomain .htaccess I'll rename them using Redirect permamnent.

Though this is probably very inefficient, it'd at least get the job done.

Could you please give an example code to solve this?
It'd be of great help to many people I'm sure.

Ta!

Here's as far as I got, trying to do the two things at once, and it didn't work:

RewriteEngine on
RewriteRule ^old\.file\.name1\.htm$ [subdomain.my-domain.com...] [R=301,L]
RewriteRule ^old\.file\.name2\.htm$ [subdomain.my-domain.com...] [R=301,L]
RewriteRule ^old\.file\.name3\.htm$ [subdomain.my-domain.com...] [R=301,L]

jdMorgan

5:56 pm on Dec 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, for example: [yellow.colours.com...] actually points to: [colours.com...]
The yellow subdomain appears as a folder in my main directory.

This is similar to what I use to define a "test" subdomain for testing code without affecting the live site:

RewriteCond %{HTTP_HOST} ^yellow\.my-colours\.com
RewriteCond %{REQUEST_URI} !^/yellow
RewriteRule (.*) /yellow/$1 [L]

I'm not clear on how your "yellow.pale" requirement fits in here, because I'm not sure if "yellow.pale" is part of your subdomain name or part of your URI. Fixing that should be easy, once the problem is defined.

A map of the full transformation is most useful in these cases, for example:

yellow.my-colors.com/<whatever> --> yellow.my-colors.com/yellow/<whatever>
maps out the action of the above rewrite code completely, the only missing map detail being that the user will not see the /yellow/ subdirectory, only the yellow subdomain, in the browser address bar.

Please give us more details of your required y.2.html to yellow.pale.html transformation - it's a question of where does the information needed to decide you want "pale" come from in the original user-requested URL.

Jim

Angonasec

11:56 am on Dec 29, 2003 (gmt 0)



Thank you for your reply Jim, I really appreciate your help, forgive me for confusing you, I'm afraid I've not made clear what I'm after.

I'm not trying to create, or move, a subdomain or folder at all. I already have the subdomain. (it is set up by my host as a DS-IRM). I'm simply trying to redirect calls for files that I've moved from the main directory to the subdomain. That's all I really need. If possible I'd like to rename each file too, but as I said above, I can do that using Redirect in the subdomain's htaccess file.

Perhaps if I gave a completely new ficticious example to remove any confusion:

Say: I have six files in my main directory of my domain: fred.com
They have uninspiring names like f.1.htm, and f.37.htm, etc

I already have a functioning subdomain on the site called: [features.fred.com...] and I'd like to move the six files there permanently. That's all!

So, [fred.com...] calls are redirected to: [features.fred.com...]

and [fred.com...] calls are redirected to: [features.fred.com...]

This is such a basic question it's not answered in any of the docs or threads I've read so far!

No doubt the answer is too obvious to all ... except me.

The extra complexity mentioned, is that I'd like to change the name of the file manually from f.1.htm to the more SE relevant: fred.at.school.htm and f.37.htm to: fred.catching.trout.htm etc.

So:
[fred.com...] ==> [features.fred.com...]
[fred.com...] ==> [features.fred.com...]

There's only six files to rename, so they can be listed individually in the mod-rewrite code.
But as I said, this is of 2ry importance. Mod-rewrite code using the exisiting file names will satisfy me, and I'll rename them using Redirect in the subdomain's htaccess.

Thank you once again for your patience, and help.

Colin

aodonline

10:06 pm on Dec 29, 2003 (gmt 0)

10+ Year Member



Im not a .htaccess guru by any means. I have a open thread right now.

But i'm thinking from things i have read that you can't have a .htaccess in the subdomain redirect a .htaccess call from the directory above. Causes a loop or stall since one mod_rewrite is tring to reroute another mod_rewrite.

I think your on the right path by calling the different name in the first .htaccess file, and as long as you call it with a 301 code, the search engines should pick up on the link change and change there links.

Angonasec

6:26 am on Dec 30, 2003 (gmt 0)



I'm not trying to do what you suggest aodonline, just moving six files from my main directory to an exising subdomain using mod_rewrite, and then in the subdomain htaccess using mod alias to rename the six files. So there's no danger of a loop.

I suspect that mod_rewrite is well able to do both things; ie. redirect and rename the files from the root htaccess file, though my more basic request will do the job.

Astonishing that there's not a single example of such a request to be found here yet.

***To prevent more confusion: I should also add JdM, that there are hundreds of files in my main directory, I ONLY want to redirect and rename six of them.***

Waiting patiently for your help ...

Angonasec

3:45 am on Dec 31, 2003 (gmt 0)



Any ideas Jim?

jdMorgan

4:31 am on Dec 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, I've been away for a few days, and I have to give my time-priority to forum92...

Here's as far as I got, trying to do the two things at once, and it didn't work:

RewriteEngine on
RewriteRule ^old\.file\.name1\.htm$ http://subdomain.my-domain.com/new.file.name1.htm [R=301,L]


Well, that should work. Let's throw out all the rest, and get *one* file redirect working.

If you put the code above in .htaccess in your top directory (not the subdomain subdirectory) then it should work. If not, add Options +FollowSymLinks before the RewriteEngine on.

Now if that doesn't work, you'll need to contact your host, because there is some other problem. mod_rewrite is not enabled, you don't have AllowOverride priveleges to change Options or FileInfo - something.

If you can't get mod_rewrite to work in your account, *and* if your subdomain is directly mapped to the subdirectory, then you do have the option of using the Redirect and RedirectMatch directives of mod_alias, since no conditional rewriting will be needed.

Jim

Angonasec

5:31 am on Jan 1, 2004 (gmt 0)



Thank you Jim!

Sorry to be a pest.

I re-tried my mod_rewrite suggestion for just one page, no other mod_rewrite in the root htaccess, and it did nothing, no crash, no loop, no redirect, the page stays displayed.

Follow Sym links is enabled.

It must be something weird at FQ, I'll contact the service desk about it.

But the good news is the Rediret permanent option via mod_alias *DOES* work after all. No idea why it didn't work the first time I tiried it. Likely I had a typo.

So I can achieve what I want using mod_alias, a line for each file.

When I get news from my host, I'll re-post here to enlighten us all.

Thank you for your help!

Colin

Angonasec

8:04 am on Jan 6, 2004 (gmt 0)



As promised here's the reply I got from my Host, explaining why the valid mod_rewrite redirect code would not work on my account:

"Since the IRx system is partly based on mod_rewrite support, protective measures must be taken to prevent external mod_rewrite rules from influencing how the URL is to be rewritten...

In short, our IRx system takes the URL first, does whatever transformations are necessary - and then halts any further rewrites from occurring... There is no realistic way to allow further rewrites from happening... This is for both stability and security concerns..."

So there you have it ...

Colin