How to Apache Rewrite URL without redirect? - apache

Is it possible to replace a url name like http://mysite.com/sub/ with http://sub.mysite.com using htaccess?
I don't want to make a redirect rather than just to map a sub-directory address to a sub-domain address. So when a person types an address like http//sub.mysite.com/image.jpg this address remains in the browser but it reads the content from http//mysite.com/sub/image.jpg

Yes it is possible but you should have root access to the server to start with, you will need to also make some DNS record changes so ensure you have this access also before starting.
I have used both methods previously and they both work, however I found using folders was the winner at the end of the day for our usage, this simplified things significantly for us and we didn't have to worry about changing linkages in scripts, e.g. from http://www.my-site.com/images to http://images.my-site.com depending on the code structure being used.
Instead of typing these long instructions out I am going to give you 2 references that have slightly different approaches depending on if you have a physical folder to use or if it is a variable in the URL. They say it probably as well as I can anyway ;-)
Physical folder method :: URL variable method
I hope this helps you

Related

What does the host name "ww8" stand for in URLs

Very rarely, I see URLs with a host name of "ww8" instead of "www" (e.g. http://ww8.aitsafe.com, https://ww8.welcomeclient.com/). Though rare, this appears to be consistent enough for there to be some sort of logic or history behind this, but I have not been able to figure out what it could be about.
Does anyone know what the host name "ww8" stands for and when it is used? Or is this simply a random peak of arbitrarily chosen non-standard hostnames?
This is a subdomain system to identify subdomains. ww8 means that is the 8th subdomain. This system is used to balance load on the server side

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.

Planning url rewrite for my web app

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.

Apache redirect when users home directory is completely empty

I work for an ISP and I have a server with thousands of users 10MB of free storage. They get this free storage with every e-mail account they have with us. An example of a users storage address: http://users.example.com/~username/
One problem I can see is scanning the server for user names to see what accounts are available, basically getting a list of all our customers valid e-mail addresses. This would be very, very bad.
So I'm wanting to redirect to our homepage if someone comes across a users account that is empty (I'd say 90% of them are completely empty). I also do not want to simply -Indexes them and use a custom 403 because the few customers that do use them, want +Indexes.
I know I can always just tell the customers to put a htaccess file in their directory with Options +indexes if they want directory listing, but that's a last resort.
How can I make it pretty much impossible to tell what accounts are on the server but not in use at all?
I can't see a way to do this with Apache rules alone - and even if, it would be pretty expensive, scanning for files on every incoming request.
I would build a script that puts the appropriate .htaccess file, redirecting to your home page, into every completely empty account.
Maybe run it hourly, and make users aware that if they populate a directory for the first time, it may take up to an hour until their changes take place? I think that would be a reasonable time frame.