Forum Moderators: phranque

Message Too Old, No Replies

Why does my RewriteRule cause a Server 500 Error?

Trying to invisibly rewrite a parked domain to a folder and wildcard files

         

Wizcrafts

5:58 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



This is a thorn in my side for a long time now. I have several parked domain names on my shared hosting website. The ones that only go the the web-root automatically maintain their own domain name in the browser's addressbar. Any that are forwarded to a specific file or sub-folder show the actual path on my master domain, instead of the parked name/filename.

If I use the flags [R=301,L] or [R=302,L], then the rule functions and transfers the request to the specified file or folder. However, it loses the parked domain name in the process. If I remove the R=301 or 302 flag I get a server 500 error when I try to access the URL controlled by the ruleset.

Here is an example of the one I am trying to get going right now, which is causing 500 errors unless I include the R=301 or R=302 flag. Assume that my actual domain is called example.net:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_REFERER} example\.info [OR]
RewriteCond %{HTTP_HOST} example\.info
RewriteRule ^(.*)$ Folder/$1 [R=302,L]

### (This RewriteRule functions, but shows my actual domain and location in the addressbar (ht*p://www.example.net/Folder/file), not the parked domain - example.info/Folder/file.)

# RewriteRule ^(.*)$ Folder/$1 [L]
## (This commented-out RewriteRule causes a server 500 error but displays the correct parked domain name, example.info/Folder/file, in the addressbar!)

Is there anyway I can get the parked domain name to display in the addressbar without causing a server 500 error? Can somebody explain why using only the L flag causes a 500 error? I have read that using only the L is how one performs an invisible rewrite from one uri to another.

Thanks, Wiz

jd01

6:12 pm on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1. Are your rules in the .htaccess or in the httpd.conf file?

2. Are you using the commented out rule with the conditions or as it appears without the conditions? If you are using it without the conditions, there is an infinite loop created, because there is nothing to stop Folder from being rewritten to Folder/file.html to Folder/Folder/file.html to Folder/Folder/Folder/file.html and on and on...

RewriteCond %{HTTP_REFERER} example\.info [OR]
RewriteCond %{HTTP_HOST} example\.info
RewriteRule ^(.*)$ /Folder/$1 [R=302,L]

RewriteCond %{REQUEST_URI} !^Folder
RewriteRule ^(.*)$ /Folder/$1 [L]

I have assumed the rules are in the .htaccess and added a preceding / to the right side. I also added a condition that should break the loop. The rewrite will only be performed on URI's that do not start with Folder.

3. Can this information be accessed from the main domain by users of that domain? If so, are you really trying to create multiple duplicate content domains?

Hope this helps.

Justin

jdMorgan

6:25 pm on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



REQUEST_URI will always have a leading slash, so:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.info
RewriteCond %{REQUEST_URI} [b]!^/F[/b]older/
RewriteRule ^(.*)$ /Folder/$1 [L]

I would think that your error log would clearly show the cause of a 500-Server Error. What does it say?

Start-anchor the domain if possible, as shown -- "(www\.)?" makes "www." optional.

I recommend that you do not bother with rewriting based on HTTP_REFERER -- it's likely to cause very 'weird' problems.

Jim

jd01

6:31 pm on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, Jim... I always forget that one until I get an error - Don't know why it escapes me every time, but it does.

Justin

Wizcrafts

6:53 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



JD01 asked:
1. Are your rules in the .htaccess or in the httpd.conf file?

They are in my .htaccess file. I don't have access to .httpd.conf because I am just renting space on a shared hosting company's server.

2. Are you using the commented out rule with the conditions or as it appears without the conditions?

I tried using it in place of the rule ending with [R=312,L]. I just switched the comment # to that line of code to make the one without the R Flag active. That caused the 500 error. So it was part of the RewriteCond group, and not stand-alone.

3. Can this information be accessed from the main domain by users of that domain? If so, are you really trying to create multiple duplicate content domains?

In this particular case I have a website that I created for a friend, on my server space. He asked if it was possible to reference it with his own domain name, without the added expense of having his own hosting company. I got a free .info domain name in a promotion from my registrar and pointed it to his already existing content, which I referred to as "/Folder/." That content is accessible via my example.net website. I am trying to give him a means of promoting his website to his friends, without them having to see that it is part of somebody else's website (mine). This has nothing to do with trying to fool robots. It is for human convenience.

If you are using it without the conditions, there is an infinite loop created, because there is nothing to stop Folder from being rewritten to Folder/file.html to Folder/Folder/file.html to Folder/Folder/Folder/file.html and on and on...

When I added a new Condition for !Folder the invisible Rewrite worked perfectly! It was going into an infinite loop. Thanks JD01.

Here is what I ended up with, that works to give my parked domain an invisible rewrite in the browser, to a specified directory, with wildcards:

RewriteCond %{HTTP_REFERER} example\.info [OR]
RewriteCond %{HTTP_HOST} example\.info
RewriteCond %{REQUEST_URI}!^/Folder/
RewriteRule (.*) /Folder/$1 [L]

Thanks for the help and thanks to WebmasterWorld for providing this extraordinary Forum!