2

I have sat up two virtual host on the same ip and same document root with Apache, because I want to use shared files and contents in the document root.

I want my second website point to a subfolder of the document root

http://example.com Loads http://example.com/subfolder

I tried various rewrite rules in the .htaccess they all can redirect but maintain the subfolder in the url which I dont like I mean the url would be

 http://example.com/subfolder

while I want

 http://example.com

these are what I have tried

RewriteCond %{HTTP_HOST} ^(www.)?example.com$   
RedirectMatch ^/$ http://example.com/subfolder

OR

RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(.*)$ /subfolder/$1 [L]

the second one also gives a 500 Internal Server Error, what should i do?

3 Answers 3

6

What you want to do is not make a redirect but to rewrite the query with RewriteRule. So it should be like this:

RewriteCond %{HTTP_HOST} ^(www.)?example1.com$   
RewriteRule !^subfolder1/ subfolder1%{REQUEST_URI} [L]
RewriteCond %{HTTP_HOST} ^(www.)?example2.com$   
RewriteRule !^subfolder2/ subfolder2%{REQUEST_URI} [L]

F.ex. the query http://www.example1.com/foo.html will be treated by Apache like it was a query http://www.example1.com/subfolder1/foo.html. Change the domain in this query and the file will be served from subfolder2.

While testing my solution I found also this, quite similar to your problem:
Request exceeded the limit of 10 internal redirects due to probable configuration error.?

2
  • just a little problem, it rewrites every file to subfolder2, what if I just want to rewrite php files and use for example the javascript and css files from the document root (the parent)
    – Ahmad
    Feb 21, 2014 at 13:19
  • 1
    thank you it seems I find the solution to exclude some files by RewriteCond %{REQUEST_URI} !\.(css|js)$ [NC]
    – Ahmad
    Feb 21, 2014 at 13:36
1

The term "Redirect" means that your server tells the browser to go fetch another page instead of the one it asked for. When the browser does that, it will also update the path in the Location bar.

In order to hide the new location, you need to instead use mod_rewrite. That is a module that will look at what the server asks for and translate it to a different place on the server, without issuing a redirect.

2
  • Thank you, and sorry for mistyping the second try. I modified my question, actually I also tried Rewrite but they also doesnt work
    – Ahmad
    Feb 21, 2014 at 9:31
  • Turn on rewrite logging and add the logs to the question
    – Jenny D
    Feb 21, 2014 at 9:32
0

How would i make these ssl? I'm using this...

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www.)?domainone.com$
RewriteRule ^(?!domainone/)(.*)$ /domainone/$1

RewriteCond %{HTTP_HOST} ^(www.)?domaintwo.com$
RewriteRule ^(?!domaintwo/)(.*)$ /domaintwo/$1

RewriteCond %{HTTP_HOST} ^(www.)?domainthree.com$
RewriteRule ^(?!domainthree/)(.*)$ /domainthree/$1
1
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – Dagelf
    May 27, 2022 at 10:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .