azunoman Posted March 20, 2012 Share Posted March 20, 2012 I am running multiple tld's using domain alias from my hosting account. When my site gets control it checks the $_SERVER['HTTP_HOST'] to see if it's what's defined in my allowed tld table and if so updates the CMS core with the tld domain name and other details used by the CMS. The aliases address appears as expected in the address bar. Works great! I have been looking at other options outside of domain aliasing, because of email issues and some people may not have the capability to define a domain alias easily. -I've ruled out frame(masked) forwarding as this won't work with paypal and other payment gateways I suspect. Nor is it SEO friendly at all, etc. -For regular 'parked' unmasked forwarding I do not receive the original url 'referrer', but will test again. :DMy question is how can I use a 301 redirect and keep the tld coming into the the main domain in the address bar? I also need to check if it's a redirect and that the referrer is in my tld table, and if so execute code like I do for alias. i.e. .htaccess redirect in domainone.xx to domaintwo.xx with domainone.xx still in the address bar. here is the example I've used for 301's that I don't want the redirected site to display in the receiving domain. Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^www.old-domain.com$ [NC] RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,L] I really appreciate review of the freaks. Quote Link to comment https://forums.phpfreaks.com/topic/259372-htaccess-rewrite-301-but-passing-the-original-url/ Share on other sites More sharing options...
azunoman Posted March 20, 2012 Author Share Posted March 20, 2012 p.s. I little incentive, on scouts honor. anyone solving this issue I'll send $25.00 via paypal it's not much but maybe a light dinner for two. Quote Link to comment https://forums.phpfreaks.com/topic/259372-htaccess-rewrite-301-but-passing-the-original-url/#findComment-1329638 Share on other sites More sharing options...
TimeBomb Posted April 1, 2012 Share Posted April 1, 2012 .htaccess redirect in domainone.xx to domaintwo.xx with domainone.xx still in the address bar. From my experience, .htaccess redirect can't do exactly what you want it to (all by itself, anyway). Normally, when you want two domains to point to the same spot, you just set up another virtual host with Apache wherein the folder goes to the same location as the original domain, but the domain is the alternative domain. Alternatively, you may also try looking into Apache's ServerAlias directive. If you require a 301 redirect when the alternative domain name is used, you can send out the status code - 301 - through PHP. Look into the HTTP_HOST and REMOTE_HOST properties in the $_SERVER array in PHP, one of them should supply the information you need to detect exactly which domain name the user is viewing the website from. Using a simple conditional check, you can then optionally send out a 301 status code via: header("HTTP/1.1 301 Moved Permanently"); header("Status: 301 Moved Permanently"); // For FastCGI only I feel compelled to warn you about the correct usage of the 30x status codes. I have recently done quite a lot of research into the 301, 302, and 307 status codes for another project of mine. 301 should be used when an object has moved permanently. Thus nothing will ever be located where the old URL (i.e. where it moved from) is. 302 is the default for PHP's header function when using header("Location: http://example.com"); to redirect. It is a Temporary Redirect - in the HTTP/1.0 Status Code Definitions. In the latest, HTTP/1.1, 302 means Found and 307 means Temporary Redirect. The specific meanings between the 302 HTTP/1.0 and 307 HTTP/1.1 are slightly different as well. It all can be quite confusing, especially when knowing when to use them and when not to. The HTTP/1.1 Status Code Definitions can be found at: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html Google is also a powerful tool. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/259372-htaccess-rewrite-301-but-passing-the-original-url/#findComment-1333243 Share on other sites More sharing options...
azunoman Posted April 1, 2012 Author Share Posted April 1, 2012 Thanks very much for your reply Time Bomb. Here is what I am trying to do (better explanation I hope) I have a module for a cms, it reads the http_host name and if it's in my database I switch the hard coded cms core url with the http_host. Then let the cms proceed naturally. Thus allowing more than one domain name to run on the cms. I am currently testing using aliasing and it works fine but any forward I use either the hosting providers interface for park/park frame or .htaccess I can not compare the http_host. Nor is there anything in the referrer or forward server variables. And I agree with your advice on 301/302. I will use a 302 on the .htaccess or actual php code if I can read the original url referrer. I am hoping to offer alternative method(s) to customers that use this module to point their other domain name(s) to the cms and which my module can read and take appropriate action. Quote Link to comment https://forums.phpfreaks.com/topic/259372-htaccess-rewrite-301-but-passing-the-original-url/#findComment-1333256 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.