0

I have the following DocumentRoot structure on my webserver:

folder1
folder2

I can access all of them in standard way

my.ip.address.here/folder1
my.ip.address.here/folder2

I want to redirect the request to website that doesn't have particular folder specified to one default folder, namely 'folder1'. For example, if I type in a browser my.ip.address.here, it redirects me to 'my.ip.address.here/folder1'. I have the .htaccess file located inside my DocumentRoot folder with the following contents:

RewriteEngine On
RewriteRule ^$ /folder1 [R=301, L]

When I run the website in a browser I get the following eror:

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

Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

What could be wrong with configuration? Thanks in advance!

Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488
  • this is dupliate of [use-mod-rewrite-to-rewrite-root-to-another-path](http://stackoverflow.com/questions/2766443/use-mod-rewrite-to-rewrite-root-to-another-path) – V-X Jul 24 '13 at 06:51

1 Answers1

0

If you simple want to redirect internally or not / to folder2 any of these rules would.

Redirect 301 using a rule:

RewriteRule ^$ /folder2 [R=301,L]

Internally the URL does not change:

RewriteRule ^$ /folder2 [L]

Use 302 if you want a temporary redirect and 301 for permanent redirect.

Prix
  • 19,417
  • 15
  • 73
  • 132
  • wouldn't this redirect my.ip.address.here/folder1 to http://www.forth.com/folder2/folder1? – V-X Jul 24 '13 at 06:53
  • I think, this doesn't match the OP's requested behaviour. – V-X Jul 24 '13 at 06:55
  • I think, OP only wanted to redirect root without any path to folder2. – V-X Jul 24 '13 at 07:00
  • Yes, V-X is right. I wanted to redirect root without any path to folder2. – Max Koretskyi Jul 24 '13 at 07:01
  • @Prix, I get cyclic error if I use first option - Redirect 301 / /folder2. – Max Koretskyi Jul 24 '13 at 09:02
  • @Maximus indeed the `Redirect` rule is not applicable however the `RewriteRule ^$ /folder2 [R=301,L]` works as expected. – Prix Jul 24 '13 at 09:08
  • @Prix, it's weird, because I still have this cyclic error and the URL in browser shows the following: http://my.ip.address.here/folder2/folder2 – Max Koretskyi Jul 24 '13 at 09:29
  • @Maximus do you have any other rules in place ? I just double checked it and it works just fine. – Prix Jul 24 '13 at 09:38
  • @Prix, nope, this is the lines I have in .htacces: `RewriteEngine On RewriteRule ^$ /selfstudyclub.com [R=301, L]`. And I get the following in browser - `http://my.ip.address.here/selfstudyclub.com/selfstudyclub.com/selfstudyclub.com/selfstudyclub.com/selfstudyclub.com` – Max Koretskyi Jul 24 '13 at 09:46
  • Its possible that your browser have cached from the previous rule since it was using 301 try changing it to folder1 for example and use 302 instead of 301 – Prix Jul 24 '13 at 09:49
  • Thx, but the problem seems to be even worse. When I used other browser it returned 'Internal Server Error'. What can be wrong here? – Max Koretskyi Jul 24 '13 at 09:54
  • @Maximus [update your question with the exact content of your .htaccess file](http://stackoverflow.com/posts/17826991/edit) – Prix Jul 24 '13 at 09:55
  • @Maximus you can move it back to folder2 the cache should be gone by now. – Prix Jul 24 '13 at 10:12
  • @Prix, I used different browser so the problem now is not about cache, although cyclic references were caused by cache in Chrome – Max Koretskyi Jul 24 '13 at 10:54
  • @Maximus have you put the redirect back to folder2 ? does it still give you Internal Server Error? – Prix Jul 24 '13 at 10:55
  • Yes, I redirect it to folder2 now, but still get this error. Moreover, I get this error even if I try the following URL: `my.ip.address.here/folder2` which works fine when there is no .htaccess file in place. This is madness... Thanks for you patience, I'll try to figure out what's wrong later. I guess I'll have to check the logs – Max Koretskyi Jul 24 '13 at 11:16
  • @Maximus yes checking the error_log, and rewrite_log will help, keep in mind the rule itself works I have tested it myself on my localhost, You might need to activate the `RewriteLog` as follow: `RewriteLog "/your/path/here/logs/rewrite_log"` and the level `RewriteLogLevel 9` – Prix Jul 24 '13 at 11:22