3

I have a CMS installed on a subdomain (say blog.domain.com). I created a site on it but the site can be accessed at (blog.domain.com/sites/mysite). I also have to use other links like blog.domain.com/#/create and blog.domain.com/#/login/mysite

How do I achieve the following things:

  1. Redirect all requests to blog.domain.com to blog.domain.com/sites/mysite WITHOUT changing the URL.
  2. Still have access to blog.domain.com/#/create and blog.domain.com/#/login/mysite

I know there are a lot of answers on .htaccess redirects but I cant find the complete answer for both my questions above.

1

In your subdomains document root, try the following:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/sites/mysite/
RewriteRule (.*) sites/mysite/$1 [L]

Since this is an internal rewrite, you don't need to do anything with regards to #2

|improve this answer|||||
  • thanks for your response @DocRoot. There are two things that are happening: 1. The above rule redirects to blog.domain.com/sites/mysite but the url isn't changed. it should remain blog.domain.com 2. I am still unable to access blog.domain.com/#/create. It redirects me to blog.domain.com/sites/mysite/#/create – takeradi Mar 16 '16 at 14:22
  • "but the url isn't changed" - I assume you mean "is changed"? Try clearing your browser cache. The above directive shouldn't be redirecting. The URL should not change. If you've been testing redirects (ie. R=301) then these will have been cached by the browser. – DocRoot Mar 16 '16 at 14:50
  • yep. i did that. no luck. i use chrome by default but i also used firefox and safari in this case to verify. – takeradi Mar 16 '16 at 14:53
  • Do you have any other directives in your .htaccess file? Is your subdomain stored in a subdirectory off the main domains document root, and this .htaccess file is in that subdirectory? Try removing the slash prefix on the RewriteRule substitution (I'll update the answer). – DocRoot Mar 16 '16 at 14:57
  • i cleared the cache again. that works partially. i see the site has been redirected but i get some javascript errors because its looking for a javascript file under the main directory instead of the mysite directory. and the second one doesnt work at all – takeradi Mar 16 '16 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.