Redirect domains single pages and maintain url

Redirect domains single pages and maintain url - .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 domains, htaccess, redirects, , .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 several domain names that need to point to individual pages on a single host and still maintain the URL. For example:



examplesite1.com needs to point at mainsite.com/examplesite1.php but still display examplesite1.com



examplesite2.com needs to point at mainsite.com/examplesite2.php but still display examplesite2.com



The host doesn't allow parked domains and has very limited add-on domains, so it seems my only way of linking the domains is via web forwarding. I can get the forwarding to arrive at the correct pages, but I don't seem to have any control over it with .htaccess and therefore the actual URL displays - presumably because the redirect happens prior to arriving at the host.



Is there any way around this? I'd rather not use the registrar's cloaking or use frames if I can avoid it.



Edit: Requested info



I have tried to implement this, examplesite1.com is set to forward to mainsite.com



RewriteEngine On
RewriteCond %HTTP_HOST ^(www.)?examplesite1.com$
RewriteRule ^(.*)$ http://www.mainsite.com/examplesite1.php [R=301,L]


I've also tried several variations of similar .htaccess rules but nothing has any effect at all.



I have tried doing this with the 1 add-on domain that I'm allowed, adding examplesite1.com as an add-on domain. This results in the correct page loading, but it displays the 'actual' url


Solution :

If the URL changes then it's a redirect if doesn't then its not a redirect... there's no workaround. You don't want a redirect method as it won't work.



Theses are just some methods that will work:





I'm not going to explain every method since you can find all this info on stack overflow.



Shared Hosting



This is the easiest method.



Lets say you have:




  • Mainsite = var/www/




    • SiteA = var/www/siteA

    • SiteB = var/www/siteB




      1. Make a index.php file in SiteA with <?php include 'var/www/examplesite1.php';

      2. Make another file in SiteB with <?php include 'var/www/examplesite2.php';




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