DirectAdmin - 2 .htaccess files - setup problems sub domains

Using a single web hosting account to host multiple sites

DirectAdmin - 2 .htaccess files - setup problems sub domains

Postby ikke » Thu Oct 16, 2008 2:15 am

Currently we use DirectAdmin on our dedicated server. For each website/url we have set up an account.
When I use the file manager I see in the map public_html an .htaccess file containing the following (This is what the server/directadmin sets up by default. )


RewriteEngine On

RewriteCond %{REQUEST_URI} !^/~accountname/domain.com(.*) [NC]
RewriteRule ^(.*)$ /~accountname/domain.com/$1

accountname=account name for this account as set up by us on the server
domain.com is the name of the associated domain

In the lower directory name domain.com there are several folders (folders for created sub domains on the server - without .htacess) and files:
amongst others there is another .htaccess file containing the following:

Options +FollowSymLinks

RewriteEngine On

RewriteRule Google http://www.google.com/? [NC,R]

When I go to http://domain.com/google the redirect is being performed. When I move the RewriteRule Google to the other .htaccess file the redirect is no longer being performed.

So I have to put the mod rewrite rules in the sub folder called domain.com. But rules for sub domains are not working. How can I write rules for the sub domains?

Really appreciate you help.
ikke
 
Posts: 9
Joined: Fri Jul 11, 2008 5:53 am

Postby richardk » Thu Oct 16, 2008 7:19 am

So rules in /~accountname/example.com/sub/.htaccess do not work?

Try (in /~accountname/example.com/sub/.htaccess)
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteOptions Inherit

RewriteRule Google http://www.google.com/? [NC,R,L]

Does it redirect if you go to http://sub.example.com/google?
Does it redirect if you go to http://example.com/~accountname/example.com/sub/google?
Does http://example.com/~accountname/example.com/sub/google redirect if you remove /public_html/.htaccess?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

thanks! few follow up questions

Postby ikke » Fri Oct 17, 2008 1:11 am

Thanks again for your great help Richard!

So rules in /~accountname/example.com/sub/.htaccess do not work?

>the rules for the subdomains do not work (and there is no .htaccess file in the map for the created sub domains) only 1 in the lower directory name "domain.com". I would like to create and use rules for sub domains just by editing 1 .htacess file and without having to create submaps on the server (especially as I would also like that ruels for wildcard sub domains work)

----------------------------------

When I put

Options +FollowSymLinks

RewriteEngine On

RewriteOptions Inherit

RewriteRule Google http://www.google.com/? [NC,R,L]

in the higher level .htaccess file (in the map public_html) (and not in the lower map .htacess file in the map example.com):

It does not redirect if I go to http://example.com/google (404 not found)

It does not redirecy if I go to http://example.com/~accountname/example.com/sub/google?

I have not tried: "does http://example.com/~accountname/example.com/sub/google redirect if you remove /public_html/.htaccess?" as the Google redirect rule is only in this file.


So I think this is not what you have meant and so I also tried the only other option:
-----------------------------

When I put

Options +FollowSymLinks

RewriteEngine On

RewriteOptions Inherit

RewriteRule Google http://www.google.com/? [NC,R,L]

in the lower level .htaccess file (in the map example.com) (and not in the higher map .htacess file in the map public_html):

the higher map .htacess file in the map public_html contains:
RewriteEngine On

RewriteCond %{REQUEST_URI} !^/~r8km1info/8km1.info(.*) [NC]

RewriteRule ^(.*)$ /~r8km1info/8km1.info/$1



Does it redirect if you go to http://sub.example.com/google? YES!

Does it redirect if you go to http://example.com/~accountname/example.com/sub/google? YES!

Does http://example.com/~accountname/example.com/sub/google redirect if you remove /public_html/.htaccess? YES!

What shall I do Richard? Do I have to restore /public_html/.htaccess file?

The rule now also works for sub domains (which have been created on the server), but not for the non existing (wildcard sub domains). Then I get the message: "Apache is functioning normally" when I go to such a non existing (wildcard sub domain) and the /google I get a 404 error.

Is there a solution for these (wildcard sub domains)?



---------------
Follow up question:

we would also to use the following rule:


RewriteCond %{QUERY_STRING} ^(.*&)?q=1(&.*)?$ [NC]
RewriteRule ^$ http://example.com/new-url-1?%1%2 [R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?q=2(&.*)?$ [NC]
RewriteRule ^$ http://example.com/new-url-2?%1%2 [R=301,L]

is it possible to integrate another rule? That is: if q=2 then the parameter c= (when this parameter appears in the url) then this parameter will be changed into the parameter m=
For example: test.com?q=1&c=aa will then redirect to http://example.com/new-url-1?m=aa (and test.com?a=1&c=aa&q=1 will then redirect to http://example.com/new-url-1?a=1&m=aa)
ikke
 
Posts: 9
Joined: Fri Jul 11, 2008 5:53 am

Postby richardk » Fri Oct 17, 2008 9:03 am

Do I have to restore /public_html/.htaccess file?

Do the normal site URLs work OK? If the do you do not need to restore /public_html/.htaccess.

Is there a solution for these (wildcard sub domains)?

Did they ever work? To get them to work you would probably need to find a DircetAdmin setting or manually edit your httpd.conf file (which might conflict with your DirectAdmin settings).

For example: test.com?q=1&c=aa will then redirect to http://example.com/new-url-1?m=aa (and test.com?a=1&c=aa&q=1 will then redirect to http://example.com/new-url-1?a=1&m=aa)

Try
Code: Select all
# Get everything before and after q=1.
RewriteCond %{QUERY_STRING} ^(.*&)?q=1(&.*)?$ [NC]
# Get everything before and after c (c=).
RewriteCond %1%2 ^(.*&)?c(=.*)$ [NC]
# Put m in place of c.
RewriteRule ^$ http://example.com/new-url-1?%1m%2 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Thanks + follow up

Postby ikke » Fri Jan 16, 2009 4:37 am

Hi Richard,

Thanks for your reply above. I use this mod rewrite with a lot of satisfaction!

I do have a follow up question:

Currently I have the following mod rewrite:
----------------------
Options +FollowSymLinks

RewriteEngine On

RewriteOptions Inherit

# TESTCASE Get everything before and after q=605.
RewriteCond %{QUERY_STRING} ^(.*&)?q=605(&.*)?$ [NC]
# Get everything before and after c (c=) (c= changes into p=)
RewriteCond %1%2 ^(.*&)?c(=.*)$ [NC]
RewriteRule ^$ http://example.com/click?%1p%2 [R=301,L]

-----------------------

Currently I would like to add an addtional similar rule to: RewriteCond %1%2 ^(.*&)?c(=.*)$ [NC] and that is: When the parameter ?g= or &g= is in the (orginal) url the new destination url the new parameter should be ?w= or &w= .
How can I add this (and similar rules) in addition to the existing rules? (so in the end when www.example.com/?q=605&c=1&g=2 the new url will be http://example.com/click?p=1&m=2

Thanks again, your help is appreciated!
ikke
 
Posts: 9
Joined: Fri Jul 11, 2008 5:53 am

Postby richardk » Sat Jan 17, 2009 6:13 pm

Will there always be both c and w?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteOptions Inherit

RewriteCond %{QUERY_STRING} ^(.*&)?q=605(&.*)?$ [NC]
RewriteCond %1%2 ^(.*&)?c(=.*)$ [NC]
RewriteCond %1p%2 ^(.*&)?g(=.*)$ [NC]
RewriteRule ^$ http://example.com/click?%1w%2 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby ikke » Sun Jan 18, 2009 12:32 pm

thanks again

richardk wrote:Will there always be both c and w?


not always, sorry if I was unclear. I would like to implement both rules so that if q=605 then parameter c turnes into p AND/OR parameter g turns into m

for example:

www.example.com/?q=605&c=1 changes into www.destination.com/?p=1

www.example.com/?q=605&c=1&g=2 changes into www.destination.com/p=1&m=2

www.example.com/?q=605&m=1 changes into www.destination.com/?m=2

Hope this clarifys, thanks again!
ikke
 
Posts: 9
Joined: Fri Jul 11, 2008 5:53 am

Postby richardk » Tue Jan 20, 2009 3:14 am

Ok, then try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteOptions Inherit

RewriteCond %{QUERY_STRING} ^(.*&)?q=605(&.*)?$ [NC]
RewriteCond p&%1%2 ^(p)&(.*&)?c(=.*)$ [NC,OR]
RewriteCond %1%2 ^((.+))$
RewriteCond w&%2%1%3 ^(w)&(.*&)?g(=.*)$ [NC,OR]
RewriteCond %2%3 ^((.+))$
RewriteRule ^$ http://example.com/click?%2%1%3 [R=301,L]

It's untested and probably a little over complicated. I might be able to clean it up later.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

thanks again

Postby ikke » Wed Jan 21, 2009 2:23 am

Yep this works! Thanks again.

I we would like to add a follow up rule (such as parameter label= turns into ref= ?)

can we add something like?

RewriteCond ref&%3%1%4 ^(ref)&(.*&)?label(=.*)$ [NC,OR]
RewriteCond %3%4 ^((.+))$
ikke
 
Posts: 9
Joined: Fri Jul 11, 2008 5:53 am

Postby richardk » Wed Jan 21, 2009 8:07 am

I think it should have been
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteOptions Inherit

RewriteCond %{QUERY_STRING} ^(.*&)?q=605(&.*)?$ [NC]
RewriteCond p&%1%2 ^(p)&(.*&)?c(=.*)$ [NC,OR]
RewriteCond %1%2 ^(.+)$
RewriteCond w&%2%1%3 ^(w)&(.*&)?g(=.*)$ [NC,OR]
RewriteCond %2%1%3 ^(.+)$
RewriteRule ^$ /index.php?%2%1%3 [L]


To add another you would repeat
Code: Select all
RewriteCond REPLACE&%2%1%3 ^(REPLACE)&(.*&)?SEARCH(=.*)$ [NC,OR]
RewriteCond %2%1%3 ^(.+)$

For example
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteOptions Inherit

RewriteCond %{QUERY_STRING} ^(.*&)?q=605(&.*)?$ [NC]
RewriteCond p&%1%2 ^(p)&(.*&)?c(=.*)$ [NC,OR]
RewriteCond %1%2 ^(.+)$
RewriteCond w&%2%1%3 ^(w)&(.*&)?g(=.*)$ [NC,OR]
RewriteCond %2%1%3 ^(.+)$
RewriteCond label&%2%1%3 ^(label)&(.*&)?ref(=.*)$ [NC,OR]
RewriteCond %2%1%3 ^(.+)$
RewriteRule ^$ /index.php?%2%1%3 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 24 guests

cron