Planning url rewrite for my web app - apache

I'm working on a site which shows different products for different countries. The current url scheme I'm using is "index.php?country=US" for the main page, and "product.php?country=US&id=1234" to show a product from an specific country.
I'm planning now to implement url rewrite to use cleaner urls. The idea would be using each country as subdomain, and product id as a page. Something like this:
us.example.com/1234 -> product.php?country=US&id=1234
I have full control of my dns records and web server, and currently have set a * A record to point to my IP in order to receive *.example.com requests. This seems to work ok.
Now my question is what other things I'd need to take care of. Is it right to assume that just adding a .htaccess would be enough to handle all requests? Do I need to add VirtualHost to each subdomain I use as well? Would anything else be needed or avoided as well?
I'm basically trying to figure out what the simplest and correct way of designing this would be best.

The data you need to process the country is already in the request URL (from the hostname). Moving this to a GET variable introduces additional complications (how do you deal with POSTs).
You don't need seperate vhosts unless the domains have different SSL certs.

Related

Is there a quick way to detect redirections?

I am migrating a website and it has many redirections. I would like to generate a list in which I can see all redirects, target and source.
I tried using Cyotek WebCopy but it seems to be unable to give the data I need. Is there a crawling method to do that? Or probably this can be accessed in Apache logs?
Of course you can do it by crawling the website, but I advise against it in this specific situation, because there is an easier solution.
You use Apache, so you are (probably) working with HTTP/HTTPS protocol. You could refer to HTTP referrer, if you use PHP, then you can reach the previous page via $_SERVER['HTTP_REFERER']. So, you will need to do the following:
figure out a way to store previous-next page pairs
at the start of each request store such a pair, knowing what the current URL is and what the previous was
maybe you will need to group your URLs and do some aggregation
load the output somewhere and analyze

How to direct multiple clean URL paths to a single page?

(Hi! This is my first time asking a question on Stack Overflow after years of finding answers here... Thanks!)
I have a dynamic page, and I'd like to have fixed URLs that point to different states of that page. So, for example: "www.mypage.co"(/index.php) is the base page, and it rearranges its content based on user choices. I'd then like to be able to point to "www.mypage.co/contentA" or "www.mypage.co/contentB" in order to automatically load base the page at "www.mypage.co" with the desired content.
At heart the problem is an aesthetic one. I know I could simply write www.mypage.co/index.html?state=contentA to reach the desired end, but I want to keep the URL simple and readable (ie, clean). I also, due to limitations in my hosting relationship, would most appreciate a solution that is server-independent (across LAM[PHP] stacks, at least), if possible.
Also, if I just have incorrect assumptions about how to implement clean URLs, I'd appreciate direction to a good, comprehensive explanation. I can't seem to find one...
You could use a htaccess file to redirect all requests to one location and then from there determine what you want to return to the client. Look over the htaccess/dispatch system that Tonic uses.
If you use Apache, you can use mod_rewrite. I have a rule like this where multiple restful urls all go to the same page, using regex and moving parts of the old url into parameters for the new url:
RewriteRule ^/testapp/(name|number|rn|sid|unii|inchikey|formula)(/(startswith))?/?(.*) /testapp/ProxyServlet?objectHandle=Search&actionHandle=drillIn&searchtype=$1&searchterm=$4&startswith=$3 [NC,PT]
That particular regex accepts urls like
testapp/name
testapp/name/zuchini
testapp/name/startswith/zuchini
and forwards them to the same page.
I also use UrlRewriteFilter for Tomcat, but as you mentioned PHP, that doesn't seem that it would be useful.

Proper url in address bar

I have got a site running on apache. Now I have a domain. Lets say: [www.mysite.com][1]. When I enter this it goes to for example to [www.sites/sitedirectory][2] this I see in the address bar.
How can I make sure (i think it shoult be done with .htaccess) that it will still show in my address bar [www.mysite.com][3] and not [www.sites/sitedirectory][4]
Thanks very much.
You cannot make a browser's address bar show a domain different from where the data was loaded from, for security reasons.
There are a few options:
You can set up www.mysite.com to be a proxy, which fetches content from www.sites/sitedirectory, and re-serves it, but I suspect that isn't really what you want.
You can put a web page at wwww.mysite.com which consists of one large HTML frame containing the real site at www.sites/sitedirectory. This is widely considered to be a bad idea, as (without a lot of messing about) it means that you can only ever link to the home page, and links to other sites have to be specially written to jump out of the frameset, etc, etc.
You can sort out your Apache configuration so that there is a proper vhost entry for www.mysite.com, rather than a redirect to the other URL.
Without knowing why you have got to where you are, I would strongly suggest investigating option 3.

Is serving the same website to multiple domains bad for SEO?

I'm working on a website which currently has two different domains pointing at it:
example1.com
example2.com
I have read that serving identical content to multiple domains can harm rankings.
The website being served is largely the same with the exception of item listings (think of an e-commerce site) and a few other minor tweaks (title, description, keywords, etc). Depending on the domain used it will adapt to serve different items.
Does this resolve the issue of serving duplicated content across multiple domains thus not harming the rankings?
Or would I be better to 301 redirect to a single domain and go from there?
If both your URLs show the same styled product listing then it will definitely affect the search engine result. Give a different look to both your websites in terms of displaying product or changing navigation menu. Put a slightly different image and add different descriptions to display your product.
If you run a website with same content and design on two different domains even with modified title, description and keywords, it is bad SEO practice and your website will be penalized by search engines.
Best option would be making a new website design with original content for the second domain and optimize it. Other wise you can make a 301 redirect for pointing domain 2 to the domain 1, this will not harm you nor help you!
I have also seen multiple domains having same website, content, title and description.. But to my surprise that domain is ranking well.. Crazy search engines!

stacks of domains, positive SEO?

I have a client who has brought a truck load of domains he wants me to redirect to his site.
A few of them are the same name with different top level domains (mysite.com, mysite.co.uk etc etc) but a lot of them are keyword related (mylocation-businessType.com etc etc).
I am wondering if either of these will be negative for SEO. I am thinking the top level domain changes will be fine, and expected by google, but the keywords might be views as a bit hacky?
What are the good people of stackoverflow's view on this?
If they are redirected properly then they'll have no effect at all. The only advantage will be if the name makes sense and a user might type it in. eg. identical names with and without hyphens.
For this situation all of the other answers are correct, you won't get any benefits in Pagerank, etc. and it wouldn't be useful except to pickup direct traffic to your domain names that you are then redirecting.
How would it affect your SEO though? That's a little trickier. Two ways of looking at it:
1.) Competitors could do this to you and it'd be completely out of your control. If redirecting a bunch of domains did any real harm to rankings it'd be a great way to do negative SEO, or "Google Bowling," and could be used to take down a site's rankings. That isn't the case though, so it probably wouldn't have too much of a negative effect.
UNLESS
2.) The nameservers for your redirected domains match the nameservers for your main domain. Pointing all domains to the same set of nameservers will help show that all domains are under the control of the same webmaster.
Even if you are using different nameservers and using 301 redirects as recommended, if the server with your redirects comes back to (at least) the same Class C IP address as your main site's server, a search engine would still be able to tie you together as likely being run by the same owner.
Either of these setups can identify you as the source of the redirects and devalue the ranking ability of your main site since there is a much higher likelihood the redirects are coming from you.
winwaed is correct. If you're doing a proper 301 redirect, the other domains are only valuable if people directly type them in. They won't rank, won't get any link juice, and won't get any inbound links. If you do seed inbound links, google will treat them as if they point to the target of your 301 redirect. It's a waste of time to just directly do that for SEO purposes.
The way to use each of those domains for SEO would be to build a bit of unique content on each one, get some inbound links, and then link out to your target page. Not really worth doing unless you really spend a lot of time at it, and google still tends to penalize obvious gaming of the system like that.
They won't contribute toward ranking, however keyword domains do get some amount of advantage for those terms. So, the way to use them is to build sites on all of them and funnel traffic to the main site.
Of course, they can also be used for extra backlinks, but you really want different C class IP addresses from the servers. For that reason you might want to go with SEO hosting.
Matt Cutts from Google explained it in this video:
http://www.youtube.com/watch?v=r1lVPrYoBkA
and here:
http://www.youtube.com/watch?v=a70ygsHgvMw
He also said if he was doing this, he would redirect each of sites to the target sites' different important pages. If the redirected domains had pageranks before, they will still flow pagerank (not exactly but a lower pagerank).