Forum Moderators: phranque

Message Too Old, No Replies

non www url problem with directories

         

cool_jack

2:22 pm on May 25, 2008 (gmt 0)

10+ Year Member



I have redirected a directory from my main domain to a new domain. Following is the scenario:-

Directory Redirected From My main domain: www.mymaindomain.com/directory

New domain: www.directory.com

Rewrite rule used in my main domain .htaccess file:


RewriteEngine on
RewriteRule ^directory/(.*) http://www.directory.com/$1 [R=301,L]

Now I am getting a non www url problem whenever I am browsing a subdirectory of my new domain i.e www.directory.com, suppose I want to browse a subdirectory like www.directory.com/subdirectory, I always lands in non www version i.e when i click a url to a sub directory it comes as directory.com/subdirectoryrather than www.directory.com/subdirectory and it is happening with all the subdirectories in this particular domain. Outside the subdirectory it is coming as www version but whenever i enter a subdirectory it automatically comes out in non www version.

Please help so that i get the www version of the whole domain.

[edited by: jdMorgan at 2:59 pm (utc) on May 25, 2008]
[edit reason] de-linked [/edit]

jdMorgan

2:56 pm on May 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The above isn't clear, since we don't know how "directory.com" is implemented -- i.e. is it on the same server or not, and if so, where it's located in the filespace, or how you "map" to it. But see the UseCanonicalName directive in Apache core; You may need to set it to "Off."

You may want to look into the details of how directory.com was set up on the server, and make sure that it was consistently defined as "www."

Be aware that mod_rewrite takes action "after the fact." You can rewrite and redirect all you want, but it is the links on your pages which "define" the URL. It wasn't clear what the directory.com links look like on your pages, but they should all be pointing to the "www" version.

Jim

cool_jack

4:11 pm on May 25, 2008 (gmt 0)

10+ Year Member



it is on the same server and all links are define as www version, i am having problem with the directories, i have link to one directory called photogallery i.e its link is defined as [directory.com...] but when i click that link it comes out in non www version i.e [directory.com...]

jdMorgan

4:50 pm on May 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You likely have a server configuration problem then. If you have a "control panel," look in there and make sure that the domain is defined as "www.directory.com". If you have access to httpd.conf or conf.d, check the ServerName and/or VirtualHost and make sure that they're defined as "www.directory.com". Also look for any internal rewrite to the filespace used to store directory.com files, and make sure that there is no redirect *after* that which would expose the internal address (this might create a rewrite/redirect loop).

And as stated above, set UseCanonicalName to "off" if the server name is defined as directory.com and not as www.directory.com.

If you do not have server config-file access, or if your control panel does not have the capabilities needed to properly configure www.directory.com, then you will have to contact your host to fix this problem.

The only way the address bar can change to directory.com after you click on a link to www.directory.com is because of an external redirect. This means that there is code or a directive on your server that is doing this. You can verify this by using the "Live HTTP Headers" add-on for Firefox/Mozilla browsers; Use it to examine your server response headers when requesting a www.directory.com URL. You will see a redirect response which sends the browser to directory.com after requesting www.directory.com. You must find the code or directive that is invoking that redirect and correct it.

Jim

cool_jack

5:31 pm on May 25, 2008 (gmt 0)

10+ Year Member



I used webbug to find the response but I can't figure out where is the problem please find the below responses.

Firstly I entered the main url i.e www.directory.com, here is the response i get,


sent Data
GET / HTTP/1.1
Host: www.directory.com
Connection: close
Accept: */*
User-Agent: WebBug/5.0

Received Data
HTTP/1.1 200 OK
Date: Sun, 25 May 2008 17:11:43 GMT
Server: Apache
X-Powered-By: PHP/4.4.6
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

Now I entered the url with the subdirectory i.e http://www.directory.com/photogallery, the response is


sent data
GET /photogallery HTTP/1.1
Host: www.directory.com
Connection: close
Accept: */*
User-Agent: WebBug/5.0

Received Data
HTTP/1.1 301 Moved Permanently
Date: Sun, 25 May 2008 17:16:47 GMT
Server: Apache
Location: http://directory.com/photogallery/
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1

f2
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>301 Moved Permanently</TITLE>
</HEAD><BODY>
<H1>Moved Permanently</H1>
The document has moved <A HREF="http://directory.com/photogallery/">here</A>.<P>
</BODY></HTML>

0

http://www.directory.com/photogallery
this part is getting the redirect problem but can't figure out where should i make the changes to fix it.

jdMorgan

6:07 pm on May 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have access to the server config files or not? If not, you're going to have to ask your host to fix this.

Jim

g1smd

6:09 pm on May 25, 2008 (gmt 0)

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



It will either be CanonicalName ON with non-www as the base server name, or it will be a redirect defined in http.conf or .htaccess.

There's no way for us to guess which one it is.

cool_jack

8:58 am on May 26, 2008 (gmt 0)

10+ Year Member



Yeah, I think I have to ask my host for fixing it...but can I turn off CanonicalName using .htaccess.