Internal redirection: Serve “/site” as “/” and “/sub/blog” as “/blog”

Internal redirection: Serve “/site” as “/” and “/sub/blog” as “/blog” - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, shared-hosting, , , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


I have a website with a shared hoster. There are a few things that I have there, like main site, Piwik, a blog and other standalone things.



Right now I have the following structure:




  • ~/subs/www gets served as example.org and www.example.org

  • ~/subs/blog gets served as blog.example.org

  • ~/subs/app/piwik gets served as app.example.org/piwik

  • ~/subs/app/foo gets served as app.example.org/foo



This is a all nice, I have separate cookies for the different applications. However, I would need a wildcard TLS certificate in order to get everything encrypted. Especially since Piwik is included in the main page, it must also be served over a secure connection. The provider wants 10 EUR/month for the wildcard certificate.



Now they offer one free certificate which I have issued for example.org and getting www.example.org for free. In consequence I would have to serve everything from example.org in order to get consistent TLS.



From a user standpoint, I would like to have the following URLs:




  • / is the main site

  • /blog is the blog

  • /app/piwik points to the Piwik installation

  • /app/foo points to some other stand-alone application



I do like the directory structure on the server, especially since I can just rsync --delete into the ~/subs/www directory and automatically prune files that I have deleted on disk. If I would upload the files such that they get served correctly, I would not do this any more.



So I would like to do this:




  • ~/subs/www is served at example.org/

  • ~/subs/blog is served at example.org/blog

  • ~/subs/app/piwik is served at example.org/app/piwik



From this question I gathered that the following .htaccess should do the trick:



RewriteEngine On
RewriteBase /

RewriteCond %REQUEST_URI !^/subs/
RewriteRule ^blog(.*) /subs/blog$1 [L]


However, when I request example.com/blog in my browser, I get redirected to example.com/subs/blog. I don't want to redirect, I want to do this mapping in the background such that the visitor will never see the URL fragment /subs/.



The shared hoster is Domain Factory, I can put in .htaccess files but I cannot alter any configuration files that need root access to the system.



How can achieve this?


Solution :

From what i gather, try this :



RewriteRule ^blog$ /subs/blog [L]


and save it in your roots (www) folder's .htaccess



But i believe that your best bet would be to do a direct redirection such as



Options +FollowSymLinks
Redirect ~/subs/blog/ http://www.yourdomain.com/blog/$1

Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect