Forum Moderators: phranque

Message Too Old, No Replies

Redirect to Another Directory

         

Bj88

7:36 am on May 22, 2012 (gmt 0)

10+ Year Member



Hello,

I am not really a scripter or programmer. I'd just like a solution! The result I am looking for is when the user opens my page I want it to redirect to another directory on the server. Reason being is the files are stored in many directories. The most important is the index.html

Some googling lead me to this code:



RedirectMatch permanent ^/$ http://domain.net/Flash Mp3 Player/project/deploy/

DirectoryIndex index.html index.shtml index.php default.html home.html


The index file is stored in the deploy folder. When I open my site I get the errors:

The server encountered an internal error or misconfiguration and was unable to complete your request.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.


If anyone could help, It'd be greatly appreciated! Thanks.

g1smd

8:39 am on May 22, 2012 (gmt 0)

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



Redirecting to a URL that includes spaces is a very very bad idea. Change that URL to use hyphens if you are going to continute using that URL (but read on).

Redirecting the root of your site to a deep page is a very very bad idea. Use an internal rewrite (not an external redirect) to serve that page when the URL "/" is requested.

Don't use Redirect or RedirectMatch on the same site where RewriteRule is in use. Use RewriteRule for all of your rules.

lucy24

10:22 pm on May 22, 2012 (gmt 0)

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



You've got two entirely separate and unrelated bits of code there. Are you on shared hosting? If so, you almost certainly don't need a DirectoryIndex line at all. You only need to include one if your normal index files have a name other than the options given in the top-level config file. (The host will say somewhere.) It won't do any harm; it just isn't necessary.

NOW THEN...

Read the next bit slowly. You will think it is completely irrelevant, but it isn't.

In most Apache modules, a space has semantic meaning. For example-- deliberately taking an example from a different module--

RewriteRule foobar\.html http://www.example.com/otherkindofbar.html [R=301,L]

The first space means: the piece "foobar\.html" is the input
The second space means: the piece "http://www.example.com/otherkindofbar.html" is the desired output
The third space means: attach these extra conditions "[R=301,L]" to the Rule when you execute it

If you say

RewriteRule foo bar\.html http://www.example.com/otherkindofbar.html [R=301,L]

then it becomes

The first space means: the piece "foo" is the input
The second space means: the piece "bar\.html" is the desired output
The third space means: attach these extra conditions "http://www.example.com/otherkindofbar.html" to the Rule when you execute it

... and then Apache wigs out and throws a 500, because you have said something that makes no sense. Often your Error Logs will say exactly what's wrong. This depends partly on the Log Level, which determines how much information will be in the Error Log. If you are on shared hosting, this is out of your control.

Error messages displayed on screen are for humans visiting the site. Logs are for you, the webmaster.