0

I need help with (internal redirecting?) using apache's htaccess.

On my server i have a main domain:

url: domain.com
server-path: /opt/public_html/domain.com/

and a subdomain:

url: sub.domain.com
server-path: /opt/public_html/sub.domain.com/

When a visitor types sub.domain.com i want the URL to be unchanged. I also want the server to serve the file /opt/public_html/domain.com/index.php to the visitor. How do i do this in .htaccess?

Also, if the visitor types sub.domain.com/sofa/ the server should serve the file /opt/public_html/domain.com/sofa/index.php without changing the URL.

Got it? OK last example:

If visitor types sub.domain.com/?big=mac the server should show the file /opt/public_html/domain.com/?big=mac without changing the URL.

Any ideas how to do this?

Ralle
  • 1
  • Sorry? so visiting `http://sub.domain.com` goes to `/public_html/sub.domain.com/`, while `http://sub.domain.com/sofa` goes to `/public_html/domain.com/sofa/index.php`? This is weird! – Lionel Chan Mar 31 '16 at 01:25
  • No. If `http://sub.domain.com` then `/public_html/domain.com/` and if `http://sub.domain.com/sofa` then `/public_html/domain.com/sofa/index.php` (or `/public_html/domain.com/sofa/` doesn't matter) – Ralle Mar 31 '16 at 01:58
  • But in your question you didn't say like that? – Lionel Chan Mar 31 '16 at 02:32
  • No. Right now http://sub.domain.com goes to /public_html/sub.domain.com/ Instead i want http://sub.domain.com to go to /public_html/domain.com/ – Ralle Mar 31 '16 at 09:29

1 Answers1

1

If you enable RewriteEngine In your .htaccess, you should be able to create a condition and rule to handle serving the main domain's pages at the subdomain URL. Something like this:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} sub.domain.com$
RewriteCond %{REQUEST_URI} !^/sub.domain.com
RewriteRule .* domain.com/%1 [L] 

The RewriteCond line makes the rule apply to any page at sub.domain.com and should be served from public_html/sub.domain.com. It should (hopefully internally) change the URI to http://domain.com/whatever without changing it in the browser.

Check out this question and this one for similar information. If .htaccess is really not working for you, you could try a proxy, mod_rewrite, or creating symlinks.

Community
  • 1
  • 1
BradzTech
  • 2,755
  • 1
  • 16
  • 21