Sub-Folder redirects

Using a single web hosting account to host multiple sites

Sub-Folder redirects

Postby lealea » Thu Oct 25, 2007 1:49 pm

I recently signed up for a new host and they have a structure I'm not familiar with and am just starting to work with mod-rewrites... at any rate i have created this type of structure for easy folder access:

public_html
-- /maindomain.net/ (sub-folder named after the main domain)
---- main domain's files and folders
-- /addons/
---- /addondomain1.com/
-------- above add-on domain's files and folders
---- /addondomain2.com/
-------- above add-on domain's files and folders
-- /subdomains/
---- /sub1.maindomain.net/
-------- above subdomain's files and folders
---- /sub2.maindomain.net/
-------- above subdomain's files and folders

At any rate, I am a beginner at this and here's what I want to do:

[1] Have /maindomain.net/ sub-folder show up as http://www.maindomain.net/ NOT http://www.maindomain.net/maindomain.net

[2] In cPanel I have made the subdomains document roots as: /public_html/subdomains/sub1.maindomain.net
Do I need to add an .htaccess mod-rewrite at all if I've already isolated that as the root? If I do need mod-rewrites, what should it be?

Thanks so much for your response. I appreciate it!
lealea
 
Posts: 8
Joined: Thu Oct 25, 2007 1:37 pm

Postby richardk » Fri Oct 26, 2007 2:17 pm

[1] Have /maindomain.net/ sub-folder show up as maindomain.net/ NOT maindomain.net/maindomain.net

In a .htaccess file in public_html/
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.net$ [NC]
RewriteCond %{DOCUMENT_ROOT}/maindomain.net%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.net$ [NC]
RewriteRule ^(.*)$ /maindomain.net/$1 [QSA,L]


[2] In cPanel I have made the subdomains document roots as: /public_html/subdomains/sub1.maindomain.net
Do I need to add an .htaccess mod-rewrite at all if I've already isolated that as the root? If I do need mod-rewrites, what should it be?

If when you go to sub1.maindomain.net you see /public_html/subdomains/sub1.maindomain.net you will not need any mod_rewrite.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby lealea » Fri Oct 26, 2007 2:25 pm

I've done this but for some reason, index.php is not being recognized as the main directory file. For example, if I go to http://www.maindomain.net/ it goes to my host's 404. But, if I go to http://www.maindomain.net/index.php it loads -- but rather improperly (the CSS doesn't load, for example).

I am running a CMS in this subfolder and I use a mod_rewrite to remove index.php from the URLs, as shown below

Code: Select all
RewriteCond $1 !^(folders|to|exclude) [NC]
RewriteRule ^(.*)$ index.php?/$1 [L]


This doesn't seem to work. This means: http://www.maindomain.net/about/ doesn't work but http://www.maindomain.net/index.php?/about/ does

My .htaccess is in my public_html root folder.

Thanks,

Lea
lealea
 
Posts: 8
Joined: Thu Oct 25, 2007 1:37 pm

Postby lealea » Fri Oct 26, 2007 2:25 pm

And yes, I have DirectoryIndex on my root folder htaccess
lealea
 
Posts: 8
Joined: Thu Oct 25, 2007 1:37 pm

Postby lealea » Fri Oct 26, 2007 2:53 pm

As I was fiddling I figured out what was the problem... I used another code you had on the forums instead... this worked:

On my root (public_html) folder's htaccess, I have:

Code: Select all
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^maindomain.net(/(.*))?$ http://www.maindomain.net/$2 [R=301,L]

RewriteCond %{HTTP_HOST} ^(maindomain\.net)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

RewriteRule ^(folders|to|exclude)(/.*)?$ - [L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.net$ [NC]
RewriteRule ^(.*)$ /maindomain.net/$1 [QSA,L]


Then in the maindomain.net subfolder, I have this htaccess:

Code: Select all
RewriteEngine On
RewriteBase /maindomain.net (the folder name)
RewriteCond $1 !^(folders|to|exclude) [NC]
RewriteRule ^(.*)$ maindomain.net/index.php?/$1 [L]
lealea
 
Posts: 8
Joined: Thu Oct 25, 2007 1:37 pm

Postby richardk » Fri Oct 26, 2007 2:55 pm

I am running a CMS in this subfolder and I use a mod_rewrite to remove index.php from the URLs, as shown below

Delete (but keep a back up copy) that .htaccess file, then try replacing
Code: Select all
RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.net$ [NC]
RewriteRule ^(.*)$ /maindomain.net/$1 [QSA,L]

with
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.net$ [NC]
RewriteRule ^(folders|to|exclude)(/.*)?$ /maindomain.net/$1$2 [QSA,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.net$ [NC]
RewriteRule ^(.*)$ /maindomain.net/index.php?/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby lealea » Fri Oct 26, 2007 3:12 pm

That doesn't work as well as the one I just posted... but I have a new problem:

I have redirects in my htaccess for certain URLs that don't exist but are there for easy access to longer URLs...

For example:

Code: Select all
Redirect /maindomain.net/blog/rss http://feeds.feedburner.com/maindomain


just /blog/rss doesn't work so I had to add the folder name to the redirect... however this automatically appends

?/blog/rss to the end of the redirected URL to make it look like:

http://feeds.feedburner.com/maindomain?/blog/rss

Is there a way to eliminate that?

Thanks so much for your help thus far.
lealea
 
Posts: 8
Joined: Thu Oct 25, 2007 1:37 pm

Postby richardk » Fri Oct 26, 2007 3:15 pm

however this automatically appends

?/blog/rss to the end of the redirected URL

Add a "?" after "feedburner.com/maindomain".
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby lealea » Fri Oct 26, 2007 3:21 pm

Works, but now there's a pesky question mark after the URL... :P Oh dear...
lealea
 
Posts: 8
Joined: Thu Oct 25, 2007 1:37 pm

Postby lealea » Wed Nov 14, 2007 12:15 pm

Is there a way to get rid of the question mark as well?
lealea
 
Posts: 8
Joined: Thu Oct 25, 2007 1:37 pm

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 26 guests

cron