Forum Moderators: phranque

Message Too Old, No Replies

need help redirecting my site to subdirectory

htaccess rewrite

         

haytekz

4:36 pm on Jun 14, 2008 (gmt 0)

10+ Year Member



i've been searching the web for solution but i can't seem to find any. i hope you could help me, as i have a feeling that here's where i can find the answers to my prayers. lol..

anyway, here's the content of my .htaccess file located in public_html folder:


# Turn on rewrites.
RewriteEngine on

# Only apply to URLs on this domain
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$

# Only apply to URLs that aren't already under folder.
RewriteCond %{REQUEST_URI} !^/subdirectory/

# Don't apply to URLs that go to existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all those to insert /folder.
RewriteRule ^(.*)$ /subdirectory/$1

# Also redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^(/)?$ /subdirectory/index.php [L]

this helped solved my initial problem of redirecting my domain name to my subdirectory. if you type in the address bar, www.mysite.com, it indeed redirects to my subdirectory and the address bar only shows www.mysite.com. but when i start clicking on links on my site, for example, if i go to the contact page, then the address bar changes to www.mysite.com/subdirectory/contact

how can i avoid this from happening? please please help me!

thanks in advance! =)

jdMorgan

5:34 pm on Jun 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is not a redirect, it's a server-internal rewrite. However, something is "exposing it" and one likely candidate would be a redirect located in code elsewhere. What do the links on your pages look like when you view page source? -- <a href= what?

Jim

haytekz

6:25 pm on Jun 14, 2008 (gmt 0)

10+ Year Member



hi Jim,


What do the links on your pages look like when you view page source? -- <a href= what?

i viewed page source, and for some reason, the links are <a href=http://mysite.com/subdirectory/pagelink>

i didnt manually code it so i dont know how that happened. i used to have my site files in the root directory (public_html) but i decided to move everything to a subdirectory instead coz its such a mess looking at my files scattered in the public_html folder, as i have lots of subdomains.

so pls tell me how i can go about doing this.

thanks!

jdMorgan

7:23 pm on Jun 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll have to find and fix whatever it is (WordPress?) that is creating the links on your pages. mod_rewrite can't "fix" this, because the links on your pages are what will show in the browser address bar -- Mod_rewrite can't do anything until the request for that link arrives at your server, and by then the user has already seen the /subdirectory-prefixed URL.

I also note that you refer to your site as "www.domain.com" while you say the links are to "domain.com". Therefore, you may also have a domain canonicalization problem. Pick www or non-www, 301-redirect the non-preferred version to the preferred version, and make sure that all links on your site consistently refer to the preferred version. This avoids duplicate-content problems which can split your page's PageRank/Link-popularity in two, and cause a search ranking loss.

Jim

haytekz

8:14 pm on Jun 14, 2008 (gmt 0)

10+ Year Member



thanks for responding Jim, appreciate it really. but im not sure im following you coz really im not a very technical person, lol..

alright how about if we put it this way. those codes i quoted above for the .htaccess rewrite, i just got them from another article. by default, my .htaccess file doesnt have anything in it, totally empty. so let's say i empty that again, how can i point my domain.com to one of my subdirectories with the url not showing the subdirectory?

jdMorgan

8:19 pm on Jun 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What I am telling you is that .htaccess code is not responsible for your problem. You have a problem with whatever it is (a script?) that is creating the incorrect links on your pages. You must fix that problem, and your .htaccess code has nothing to do with it.

That is, what you have in your .htaccess file works properly as far as it goes, but you have another problem with the configuration or code of whatever it is that creates the links on your pages.

Jim