Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mod Rewrite problem 2

Status
Not open for further replies.

gazza110

Technical User
Apr 14, 2004
42
GB
Hi,

I need help using mod rewrite to change the appearance of a URL.

I am running a virtual shop (for educational purposes only) and hosting this on my own web hosting account. I have a domain for this educational shop and this points to the actual location of the index file. I need not to show this location in the address bar.

The url looks like:


I have a domain for this of:
The domain is set to automatically redirect to the above URL. I want to change the URL as shown in the address bar to only show: and not

I have tried manipulating the .htaccess file in that directory without success.

Please can anyone help?

Many thanks, Gary.
 
My initial reaction would be to use the alias directive. Lets say for example that you use squirrelmail, which is located in some /usr/lib/smail directory. In your vhost declaration, you could define an alias /squirrelmail /usr/lib/smail and when someone tries to access domain/squirrelmail, the pages displayed will be pulled from the /usr/lib/smail directory, but the user won't know this.

So, as I said, my first inclination would be to try and setup an alias for the domain to point to where your site is really located.

If this doesn't work, the second approach I would take would be to setup a proxy host. In other words, when the client attempts to acess Apache would automatically proxy the data from your other site. I don't have an example of the syntax off hand, but this should be easy enough to find in google.
 
Thanks for the advice Noway2. The domain is not hosted, it mearly has web forwarding to I did try and use URLproxyServer.php with limited success, the page was displayed however this was then shown in the address bar as:


which still did not solve the problem :(

Can you advise me further on an alias directive, how could this be done?

Many thanks, Gary.
 
Thanks for the advice.

I have tried and failed to use the htaccess rewrite function. All I want to happen is the URL in the address bar to be changes (no REDIRECTION).

When a user enters in the address bar this is automatically sent to and displays the website I want the user to see. However they now see in the address bar and not which they originally entered.

When the user reaches I would like the address bar still to read as
Using the rewrite rule I could get it to redirect but not just stay where it was but change the URL shown.

Please can anyone help me out with this (preferably with some lines of code I might be able to use for this task).

Really appreciate everyones help on this forum.

Thanks, Gary.
 
You probably don't even need rewriting to do this. Does you hosting account allow you to have something that would phrased like: add on domains? Check you hosting control panel. This is a very common feature of many hosting accounts. Set your add on domain (educationshop.co.uk) with the path to the folder where the file are (/educationshop). Then the only other thing to do is set your nameserver info correctly at your domain registrar and that's it.
 
Thanks for the info.

Unfortunatly the hosting provider I am with does not allow me to do this nor can I change.

I really do need to do this somehow using a rewite solution.

PLEASE can anyone help with this specific request?

Thanks, Gary.
 
I'm not very good at this, but here's a stab at it. But before even trying, (since I'm not sure from the earlier part if this thread) is your DNS setup and configured properly? In other words, ignoring the URL rewriting for the moment, a ping to does correctly resolve to your webhost, correct? And using a web browser to access does cause your webhost to give a real error - either 403 (forbidden) or 404 (not found), not a generic dns error, correct?

Code:
RewriteEngine on
RewriteCond   %{HTTP_HOST}  ^[URL unfurl="true"]www\.EducationShop\.co\.uk$[/URL]
RewriteRule   ^[URL unfurl="true"]www\.EducationShop\.co\.uk(.*)[/URL] /EducationShop/$1
 
By the way, that (or something close) would need to be in the .htaccess in your webserver's docuementroot, not the /educationshop directory.
 
I just checked my apache configuration and it gave me a bit of inspiration. In my configuration, I have some websites defined that I want to catch and redirect to a new location AND show (only) the URL of the new location. In my configuration, I use "Redirect /squirrelmail
In other words, I look for the domain, with /squirrelmail and REDIRECT the query to a different page. In my case, I redirect it to the https server to enforce the use of SSL. In your case, you may try to redirect to the new URL.

With this in mind, you would want:

REDIRECT /EducationShop
As far as I know this will work in .htaccess. Note, in order to get .htaccess to work you need to set the AllowOverride all.
 

I don't think redirect is what you want. Any redirect is external. What you want is a internal rewrite,
what smah suggests. But first, it DNS must resolve as smah has said. Without that, won't work.

A redirect is only an external redirect, so it will be interpreted by the browser again.
 
Thanks again everyone for your help. I think I'm getting there but still not 100% there yet!

I have set an A Record for alias "www" of the domain "EducationShop.co.uk" to point to the ip address of my personal hosted site "
When you enter into the browser however you get a totally blank page (no error message, just a total white page).

I tried using the rewrite smah suggested however this did not seem to resolve this. I placed the .htaccess file in the root directory (public_html) and also tried putting this outside this directory in the / directory (the total root of the web directory) however this still only shows a white page.

I have ping'd the url ( and this does show online. Also checked the IP address and this showed the ip address associated to my hosting account (as per the A Record I setup).

Arghhh!! What am I not doing? Any further suggestions/help?

Thank, Gary :(
 
I think you are looping.

Things I try first:

make a file hello.txt with "hello" in it.

Disable .htaccess.
Get it from the root level with both your hosts.
and

mv the file to /EducationShop
enable the .htaccess
get the file through the rewrite
and

The rewrite should look like:

RewriteEngine on
# match host, case insensitive
RewriteCond %{HTTP_HOST} ^ [NC]
# Implied AND, which does not start with /educationshop
RewriteCond %{REQUEST_URI} !/educationshop/ [NC]
# Rewrite, permanent, last rule
RewriteRule ^(.*)$ /educationshop/$1 [R=301,L]

(I have been out of the direct apache game for a while, but this should get you going.)
 
Thanks elgrandeperro for your advice.

I have tried and failed!

When I attampted to access
Code:
[URL unfurl="true"]http://www.mypersonalhosting.co.uk/hello.txt[/URL]

This worked and the text file was displayed in the brower.

When I again tried with
Code:
[URL unfurl="true"]http://www.educationshop.co.uk/hello.txt[/URL]
noting happened, still a blank page!

I tried to use your rewrite, placing this at the web directory root
Code:
/
and also the public root
Code:
/public_html
however still nothing but a white page.

I can't understand this. The DNS is pointing to the ip address correctly (or I would get a 'page cannot be displayed' error message I presume) however it will not access anything in the directory.

Any other ideas anyone?
 
Yeah, I think your web hosting is getting in the way. Most use "virtual" named based hosting, and that matches the URL name typed to get to the right virtual host. So they don't know about so they are putting you into their "default".
 
OK - Change of plans!!

I have now transfered my domain to another provider with limited hosting.

The site files are still on MyPersonalHosting. I have created a subdomain to the EducationShop files which now looks something like:


When you access you now get a 'This page is under construction' temp holding page I put on the server.

I now need help using .htaccess Mod_rewrite to redirect to the site WITHOUT changing the URL.

I have used the following:
Code:
RewriteEngine on
 
RewriteCond %{HTTP_HOST} ^([^.:]+\.)*EducationShop\.co\.uk\.?(:[0-9]*)?$ [NC]
RewriteRule ^(.*)$ [URL unfurl="true"]http://Shop.MyPersonalHosting.co.uk/$1[/URL] [R=301,L]

This works in terms of redirecting the user to the site however this changes the URL to when I want it to remain as
I'm sure this can be done, I'm just not that good with this sort of thing.

Any suggestions/help???

Thanks, Gary.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top