Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
May 25, 2012, 11:00:06 AM

Pages: [1]   Go Down
  Print  
Author Topic: About htaccess - masked URL for subdomain  (Read 15327 times)
ryonn
Space Explorer
***
Offline Offline

Posts: 6


« on: March 15, 2011, 04:15:13 AM »

Hi there Lunarpages people,

I have a problem with masking URL for my domain.
I am looking to have a URL masking using htaccess, so that:

Whenever people type subdomainA.mydomain.com
1. they get the content of www.mydomain.com/home/id/$1
2. but the URL bar at the top still displays subdomainA.mydomain.com/$1 (hence this is not 301 redirect)

I see some websites in the Internet are able to do this

I have read and tried the solution in this thread:
http://www.lunarforums.com/search_engine_optimization/htacess_editing_mod_rewrite-t54689.0.html
But it's still not working for me.

Could you please let me know how to achieve this matter?

I am looking forward to hearing from you.

Regards,
Ryonn
Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5219



« Reply #1 on: March 15, 2011, 06:56:18 PM »

Since both are on mydomain.com, it should be possible. I think you'll have to experiment to find what your URL looks like when it comes in to your public_html/.htaccess. If it sees http://subdomainA.mydomain.com/path as HTTP_HOST = subdomainA.mydomain.com and the URI as /path, try this in your public_html/.htaccess:
Code:
RewriteEngine On
RewriteCond  %{HTTP_HOST}  ^subdomainA\.mydomain\.com  [NC]
RewriteRule  ^(.*)$  /home/id/$1  [L]
On the other hand, if public_html/.htaccess sees HTTP_HOST as mydomain.com and the URI as /subdomainA/path, you might need
Code:
RewriteEngine On
RewriteCond  %{REQUEST_URI}  ^/subdomainA [NC]
RewriteRule  ^subdomainA/?(.*)$  /home/id/$1 [L]
It would depend on how LP has set up their DNS, and is subject to change at any time. Come to think of it, you might be able to combine the two, but no promises:
Code:
RewriteEngine On
RewriteCond  %{HTTP_HOST}  ^subdomainA\.mydomain\.com  [NC]
RewriteRule  ^(.*)$  /home/id/$1  [L]
RewriteCond  %{REQUEST_URI}  ^/subdomainA [NC]
RewriteRule  ^subdomainA/?(.*)$  /home/id/$1 [L]
Play with this code and see how it goes...
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
ryonn
Space Explorer
***
Offline Offline

Posts: 6


« Reply #2 on: March 15, 2011, 07:05:42 PM »

Hi MrPhil,

Thank you for replying to my shout for help.

I have tried all 3 but it is still not working.

Should I make a subdomain of "subdomainA" in Cpanel?
If yes, what should I put in the "Document Root" and "Redirection" column?

About this:
"If it sees http://subdomainA.mydomain.com/path as HTTP_HOST = subdomainA.mydomain.com and the URI as /path"

I dont understand that part. How do I know if it is true?



In addition, I have tried this:

RewriteCond  %{REQUEST_URI}  ^/subdomainA
RewriteRule  ^subdomainA/?(.*)$   /home/id/$1  [L]

And it works for:

www.mydomain.com/subdomainA

but it doesnt work for:

mydomain.com/subdomainA
subdomainA.mydomain.com

is there something that I miss? =/
« Last Edit: March 15, 2011, 09:20:37 PM by ryonn » Logged
ryonn
Space Explorer
***
Offline Offline

Posts: 6


« Reply #3 on: March 16, 2011, 06:12:50 AM »

Hi there,

An update from me..
Somehow the cpanel subdomain works now, I manage to make:

Code:
subdomainA.mydomain.com

to display, without changing the URL, the content of:

Code:
www.mydomain.com/home/id


But there is another problem...

Since I am using a CMS to develop my website, the "id" in "/home/id" is actually a non-existent directory
Therefore, the following doesnt work:

Code:
subdomainA.mydomain.com/something.html

but the following works:

Quote

giving the error:

Code:
Not Found

The requested URL /index.php was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


I am 100% sure that the following is the problem in my .htaccess, as I have renamed the index.php to index1.php and the Not Found error above displays index1.php instead of index.php:

Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*\.html$ index.php [L]

I also have this in my .htaccess:

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteCond %{REQUEST_URI} !^/home/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /home/$1
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteRule ^(/)?$ home/index.php [R=301,L]

Please help
« Last Edit: March 16, 2011, 08:34:06 AM by ryonn » Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5219



« Reply #4 on: March 17, 2011, 05:59:01 PM »

We're going to have to see your entire .htaccess. You say "I've got this" and "I've got that" and "I've also got this" -- I have no idea how the pieces are interacting. Also, please give some examples of URLs that might come in, and where they should end up going. What the actual directory structure is would also be useful.
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
ryonn
Space Explorer
***
Offline Offline

Posts: 6


« Reply #5 on: March 18, 2011, 06:11:46 AM »

Hi MrPhil,

I finally use PHP Url Masking to handle this, it is because my directory structure is quite crazy and requires a high level of flexibility.. so yeah...
It works great.

However, I still have a problem with my subdomain: sub.domain.com

It goes up-down-up-down-up-down.
Checking the DNS it says like the following:

Code:
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_5.3 <<>> sub.domain.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: [b]NXDOMAIN[/b], id: 37728
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;sub.domain.com. IN A

;; AUTHORITY SECTION:
domain.com. 10800 IN SOA ns5.lunarmania.com. alerts.lunarpages.com. 2011030201 86400 7200 3600000 86400

;; Query time: 0 msec
;; SERVER: 172.16.12.11#53(172.16.12.11)
;; WHEN: Thu Mar 17 21:06:37 2011
;; MSG SIZE rcvd: 119


I have asked support.lunarpages and they say that the DNS checking from their place (US I guess) looks ok with no NXDOMAIN.
I'm from Australia by the way, and I have used Blackberrys, iPhones, Safari, Firefox, Chrome, IE and asked my friends, and the results is still Error504.

How come they can open it, while I cant?
Is it true that it requires some time (2-3 days) for the system to propagate?
I'm afraid that after I wait for several hours, it is still not active.
Is it possible to force the sub.domain.com to be URL/masked to domain.com/home/id ?

This is totally Sparta..

Please help.

Regards,
Ryonn

Note: as the topic is now no longer htacces, should I make another thread?

Note 2:
This is my htaccess:

Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule \.html$ index.php [L]

Code:
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/home/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? home%{REQUEST_URI} [L]

Code:
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ home/index.php [R=301,L]
Logged
ryonn
Space Explorer
***
Offline Offline

Posts: 6


« Reply #6 on: March 18, 2011, 03:13:56 PM »

Updating the DNS A Records manually solves this problem already
So I guess this thread can be closed or something.

@MrPhil, thank you for your assistance. =)
I will surely ask here again if something happens.

Regards,
Ryonn
Logged
ryonn
Space Explorer
***
Offline Offline

Posts: 6


« Reply #7 on: March 23, 2011, 08:14:39 AM »

Hi again,

While this thread has not been closed, I'll use this to ask a question about htaccess.

It seems that the global propagation of my subdomain doesnt go well.

subdomain.domain.com

is sometimes online, but it's sometimes offline. While on the other hand:

www.subdomain.domain.com

is always online.

I have tried several things in htaccess, but it's just random trial and error.
Is there a way to do URL masking

from

subdomain.domain.com

to

www.subdomain.domain.com?

Please help
I'm looking forward to hearing from you.

Regards,
Ronny

Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5219



« Reply #8 on: March 23, 2011, 06:50:39 PM »

subdomain.domain.com should always work. Adding "www." to it should normally be unnecessary (but harmless). Did you add your subdomain the normal way through cPanel or LPCP? Have you had anything done to change DNS "A" records, etc.? Do you have any domain name rewriting in any .htaccess file? That it doesn't work (or not work) consistently would lead me to suspect that it might be something more local in your ISP's DNS, rather than something at LP, although nothing's impossible! Have you confirmed that your domain name registration points to the correct LP nameservers? Perhaps one is correct and the other isn't.
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
Henry12
Space Explorer
***
Offline Offline

Posts: 7


« Reply #9 on: January 24, 2012, 01:36:26 AM »

Thank you for the information provided. The best content I've seen on this topic!
<spam links removed>
« Last Edit: April 19, 2012, 07:10:00 AM by MrPhil » Logged
Henry12
Space Explorer
***
Offline Offline

Posts: 7


« Reply #10 on: April 25, 2012, 04:23:24 AM »

This is highly informatics, crisp and clear. I think that Everything has been described in systematic manner so that reader could get maximum information and learn many things
<spam links removed>
« Last Edit: April 25, 2012, 07:27:14 AM by MrPhil » Logged
Pages: [1]   Go Up
  Print  
 
Jump to: