Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule to persist domain in addy bar?

Needing some quick help with rewrite's to keep domain in addy bar

         

DrBillNye

7:46 pm on Jul 14, 2009 (gmt 0)

10+ Year Member



First off, hi everyone, I'm brand new to webmasterworld and am really surprised I haven't stumbled upon you folks before.

I have a question that I hope is just baffling me cause my regex skills are weak and not cause it's not possible.

I have a domain (www.randomdomain.com) that I direct to a dynamically created link on another site of mine (www.maindomain.com/index.php/landing-page) but I want the address bar to retain www.randomdomain.com in order to build an additional brand around randomdomain.com and for SEO stuffs relating to that brand.

Right now I have a basic rewrite

RewriteCond %{HTTP_HOST} ^randomdomain.com$ [OR,NC]
RewriteCond %{HTTP_HOST} ^www.randomdomain.com$ [NC]
RewriteRule ^.*$ "http\:\/\/maindomain\.com\/index\.php\/landing\-page" [R=301,L]

from other posts I've read on here, I'm gathering that this isn't the best solution anyway, but I'm trying to get this to redirect but keep the location bar as randomdomain.com.

I read over the intro to mod_rewrite post and have tried to search through the forum here, but am not able to piece anything together. Anyhelp would be much appreciated.

btw this is in my .htaccess file in the root of my site. Again, thanks,

Al

jdMorgan

8:00 pm on Jul 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mod_rewrite is not the solution -- or not the whole solution, anyway. You actually need to change the DNS settings for the 'randomdomain' domain, and point that to your 'maindomain" server. This will only work if either A) you have a unique IP address for your maindomain server (you should know, because you have to pay extra for it), or B) you can use the control panel on maindomain to define an 'add-on domain'.

Once the randomdomain requests are routed to your maindomain server, you can probably use mod_rewrite to 'sort out' the two domains and handle them as you like. I say "probably" only because there will be limitations to the "add-on domain" approach that may get in your way, and it's more complex. If this is the case, then consider paying the small fee (usually around $1.00 a month) to upgrade from a shared name-based server to an IP-based virtual server.

Once you've got the above steps in place, you can take down the old server (and cancel that account), as it won't be reachable any longer.

Jim

g1smd

8:05 pm on Jul 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Looking at the code syntax, you've also got problems with escaping.

You do need to escape periods in patterns and you do not need to escape anything in the target URL.

DrBillNye

8:25 pm on Jul 14, 2009 (gmt 0)

10+ Year Member



Thanks for the reply guys. Looking at other people's code I agree I did get a little carried away with escaping. I was just excited it was working :) I'll work on tightening that up.

I am paying for the unique IP you mentioned, and I am fairly certain the DNS for randomdomain.com points to the root of maindomain.com, and to my chagrin this was the solution I came up with for sorting it out :/

It appears as though I am approaching this from the wrong angle. Which angle will give me a bit more success? (I'm not asking for free code (though I'd gratefully accept it) I just can't quite figure out which mod_rewrite syntax to apply my headaches too. Thanks again for the response

jdMorgan

9:47 pm on Jul 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I ignored the code details because of the other issues. In addition to the stuff I described above, there's another question: What is it that you actually intend to achieve here?

If your intent is to "make the same content appear on two different domains without changing the address bar," then we have a single-word synonym for that here in SEO-land: Suicide -- or the less-dramatic two-word phrase, "duplicate content" (much-covered here at WebmasterWorld and findable using the site search feature linked at the top of this page).

However, if that's the goal, and both domains already resolve to the same directory on the same server, then you might have better luck with


RewriteCond %{HTTP_HOST} ^(www\.)?randomdomain\.com [NC]
RewriteCond $1 !^index\.php/landing-page
RewriteRule ^(.*)$ index.php/landing-page [L]

But be aware that a request for *any* URL-path on randomdomain will be served with the content of index.php/landing-page

That might not sound wrong at first mention, but how about requests for images? Or for /robots.txt, /sitemap.xml, /labels.rdf, or /w3c/p3p.xml -- all "well-known," standard-name-and-location files? I doubt that you want to rewrite requests for those to your landing page! It would likely be better to "narrow down" the number and types of potentially-requested URLs that you plan to rewrite to that page.

BTW, the additional RewriteCond in the code above is intended to prevent an infinite rewriting loop.

Do consider the dupe-content and rewriting-scope caveats above; I suspect a rush to implementation before the actual requirements and effects have been studied.

Jim

DrBillNye

10:29 pm on Jul 14, 2009 (gmt 0)

10+ Year Member



Jim,

Thanks for the thought put into the response. In searching for a solution to what I was trying to do already I came across another guy who was given similar caution about the duplicate content. I'll try and find it again, but essentially the idea is to either force any link that goes specifically to the maindomain.com/landing-page (users bookmarks, or other people's links) to the randomdomain.com site, is that a correct strategy?

I'll try out the changes and be back singing your praises tonight when traffic slows down.

Thanks Jim!
Al

jdMorgan

12:21 am on Jul 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> but essentially the idea is to either force any link that goes specifically to the maindomain.com/landing-page (users bookmarks, or other people's links) to the randomdomain.com site, is that a correct strategy?

That's a different problem then, and not one addressed by the code I posted above. But let's nail down one thing here: Is it that you want to have two different Web sites 'supported' by the same "index.php" script, but serving different content? If so, that is not a duplicate-content problem, but rather just a question of sharing infrastructure between two different sites. Two sites, one server, one (shared) script...

So is that the case here?

Jim

DrBillNye

12:29 am on Jul 15, 2009 (gmt 0)

10+ Year Member



correct, one server, two sites, both sharing access to the same software framework.

jdMorgan

12:39 am on Jul 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So is "landing-page" accurately described as 'belonging to' or 'being the same thing as' the home page of randomdomain.com?

Is this maybe a 'leftover' --an artifact-- from a time before you decided to 'split' off some content into the newly-registered 'randomdomain.com'?

And is it the case that requests for maindomain.com and randomdomain.com now work normally and as required, but that you've got this artifact left over (dangling below maindomain.com, as it were) that you want to get rid of?

The problem with code is that you have to tell it exactly what you want to do... Because it will do exactly what you tell it to do... and not necessarily what you really want... :o

Jim

DrBillNye

12:56 am on Jul 15, 2009 (gmt 0)

10+ Year Member



let me try and shed some more light on what I'm doing here, i apologize if I was being too ambiguous.

I have a web store on maindomain.com with a specific product located at maindomain.com/landing-page and I have built a brand around this product, registered the domain (randomdomain.com) which relates specifically to this product and which I use heavily in marketing and the like. I like the fact that the resources are shared, cause it works akin to a loss leader, where once it's added to the cart, people shop the rest of the other site, and it's a relationship that is working very well. But now I'm here with a redirect that is doing little for me in search queries and the like, and I can't use the randomdomain.com for anything more (It's around a single product, but I would like to put up a few more pages and options) not to mention maindomain.com/index.php/landing-page/ is much harder to remember or read off your bookmark than randomdomain.com. So that's what I'm trying to do right now. Does that make sense?

jdMorgan

1:01 am on Jul 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So now, what is the exact maindomain URL we're now wanting to advertise as randomdomain? I see it posted here as both
maindomain.com/landing-page
and as
maindomain.com/index.php/landing-page/

Jim

DrBillNye

2:59 am on Jul 15, 2009 (gmt 0)

10+ Year Member



sorry, maindomain.com/index.php/landing-page

jdMorgan

3:29 am on Jul 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, as I understand it, client requests for maindomain.com/index.php/landing-page need to be 301-redirected to randomdomain.com/ and requests for randomdomain.com/ need to 'silently' invoke the script at /index.php/landing-page

So, as far as the Web is concerned, the URL is randomdomain.com/, but the filepath (not seen by the client browser, but used inside the server) is /index.php/landing-page

Notice the distinction between the URL used 'out on the Web' and the filepath used inside the server -- That's really the key to understanding this and many other URL-rewriting problems. URLs and filepaths are not at all the same thing -- or even related; They are only 'associated' by the action of a server.

If the above functional description is correct, you'll need:


# Externally redirect direct client requests for /index.php/landing-page to randomdomain.com/
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php/landing-page\ HTTP/
RewriteRule ^index\.php/landing-page http://randomdomain.com/ [R=301,L]
#
# Internally rewrite requests for randomdomain.com/ to /index.php/landing-page
RewriteCond %{HTTP_HOST} ^randomdomain\.com [NC]
RewriteRule ^$ index.php/landing-page [L]

This leaves out other domain and index canonicalization issues for the time being... One thing at a time... :)

Jim

DrBillNye

6:22 am on Jul 15, 2009 (gmt 0)

10+ Year Member



Jim sir, you are a gentleman and a scholar. It took a skosh of tweaking, but it works dandy. You guys are amazing, I can't believe how good you guys have been.

Thanks! and I'm googling canonicalization now, I'll see first if I can figure out what that means, and second how I need to fix it on my site :-)

jdMorgan

2:28 pm on Jul 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The term "canonicalization," as used here, refers to implementing redirects so that for any given 'page' or other content on your site, there is one and only one URL that can be used to reach it directly -- All other variations result in a redirect to the one "canonical" URL for that resource.

This includes casing errors, FQDN-format hostname requests, port numbers appended to the hostname, page name variations and query string variations. The idea being that search engines don't consider "files" or "pages" or anything else; The only 'objects' they consider are URLs.

Therefore, if you have more than one URL for a 'page,' then those two (or more) URLs 'compete' with each other for search rankings, and so your own pages compete with themselves, with neither doing as well as it would on its own. Some who delight in making SEO seem dangerous and mysterious refer to this as a "duplicate-content penalty," although it's actually more like self-inflicted injury; Actual search engine penalties may indeed exist for this, but if they do, they're reserved for the most egregious and intentional cases, IMO.

Consider that on a site where no steps are taken to prevent it, the following URLs may all be used to directly access the home page:

example.com/
example.com/index.html
example.com./
example.com./index.html
example.com:80/
example.com:80/index.html
example.com.:80/
example.com.:80/index.html
example.com/
example.com/index.html
example.com/?any-bogus-query-string
www.example.com./
www.example.com./index.html
www.example.com:80/
www.example.com:80/index.html
www.example.com.:80/
www.example.com.:80/index.html
www.example.com/?any-bogus-query-string

That represents a potential 14-to-one dilution of the 'ranking power' of this page, just counting those shown here. And not all variations have been shown in the interest of brevity... For example, the query string could be appended to all of the other variations as well, and the number of possible different query strings is large enough to be considered 'infinite'.

So "canonicalization" as we use it here simply means cleaning up this mess to prevent accidental or malicious dilution of page ranking.

Jim

DrBillNye

2:37 pm on Jul 15, 2009 (gmt 0)

10+ Year Member



Thanks Jim, I searched and found - [webmasterworld.com...] which has converted me to the need for a better strategy (err a strategy rather) for funneling bots and well intentioned links