Forum Moderators: phranque

Message Too Old, No Replies

Htaccess rewrite and same folder names

htaccess rewrite rules with same folder namees

         

eXistenZ

12:13 pm on Aug 16, 2010 (gmt 0)

10+ Year Member



I have tried to find the answer for almost a year now, and did ask on several different forums.
My directory structure:

/public_html/
/public_html/admin/

/public_html/domains/domain1/
/public_html/domains/domain1/admin/

/public_html/domains/domain2/
/public_html/domains/domain2/admin/

My main website is in the root /public_html/ and it's admin module is in /public_html/admin/

With RewriteCond and RewriteRule I redirect some other domains to different directories.

However, when I try to access www.domain1.nl/admin/ it will first check if there is an admin directory in the root. Because there is, it will load the wrong admin page.

I want a RewriteCond where i redirect a domainname to a different folder and always stays in that folder and not look in the root first. Is this possible?

RewriteCond %{HTTP_HOST} ^(www\.)?[a-z0-9]+\.domain1\.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/domains/domain1/
RewriteRule (.*) /domains/domain1/$1

jdMorgan

3:29 pm on Aug 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nothing wrong with your code...

Disable MultiViews/content-negotiation and AcceptPathInfo if your site does not require them; These are likely interfering with (preempting) your rule.

AcceptPathInfo Off
Options -MultiViews

Jim

eXistenZ

5:36 pm on Aug 16, 2010 (gmt 0)

10+ Year Member



I changed the .htaccess file with your solution, however it doesn't seem to change anything.


RewriteEngine On
AcceptPathInfo Off
Options -MultiViews

RewriteCond %{HTTP_HOST} ^(www\.)?[a-z0-9]+\.htaccess\.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/domains/htaccess.nl/
RewriteRule (.*) /domains/htaccess.nl/$1


www.htaccess.nl/admin/ is supposed to show www.le-romarin.nl/domains/htaccess.nl/admin/ (without password).
However it still loads the admin folders page of the root website.

g1smd

6:50 pm on Aug 16, 2010 (gmt 0)

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



HTTP_HOST can only match the domain name, not any path or query string data.

Add the [L] flag to every rule.

eXistenZ

7:49 pm on Aug 16, 2010 (gmt 0)

10+ Year Member



I don't understand what that has to do with the problem.

www.htaccess.nl/admin/ is working properly if the /admin/ foder does not exist in the root (public_html).

jdMorgan

8:04 pm on Aug 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



@g1:

In this case, "www.xyx.htaccess.nl" *is* the domain name.

@eX:
This .htaccess code must be located in the directory-path that will be traversed on the way to /admin. Based on what I can infer, that would mean this code must go into /public_html/.htaccess.

In addition, be sure that the /admin directory-path isn't Aliased (possibly in the server config file), and that if it is, that this Alias will not interfere with your rule.

Jim

g1smd

8:06 pm on Aug 16, 2010 (gmt 0)

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



@jd

OK. I misunderstood the question.

eXistenZ

8:45 pm on Aug 16, 2010 (gmt 0)

10+ Year Member



Hm, it looks like /admin/ has something to do with the alias.

www.le-romarin.nl/test/ and www.htaccess.nl/test/ seems to work.

I think I have to contact my hosting provider tomorrow and get a little bit angry.

jdMorgan

9:04 pm on Aug 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is quite usual to Alias "admin", "stats", and similar "areas" to a non-default filespace, because in this way, the scripts that implement the admin and stats functions can be "shared" across all users on the server...

That is, in fact, why I "guessed at this" as a possible cause.

So don't get angry -- at least not at first. Just ask them what the configuration is.

Jim

eXistenZ

9:22 pm on Aug 16, 2010 (gmt 0)

10+ Year Member



:) I will first at the configuration.
Then I will get angry (a little bit) for not mention it at the FAQ list.

eXistenZ

8:32 am on Aug 17, 2010 (gmt 0)

10+ Year Member



/admin/ is not an Alias as mentioned before.

I think i found the solution, but still with some strange behavior.


1. public_html/test/ has an .htaccess file to protect the page.

Options +FollowSymlinks
RewriteEngine On

AuthType Basic
AuthName "Eerst Inloggen"
AuthUserFile /location_to/.htpasswd
require valid-user


2. public_html/domains/htaccess.nl/test/ does not have an .htacces file.


When I open www.htaccess.nl/test/ it will ask for a password and www.le-romarin.nl/test/ (main site) is loaded instead of the www.htaccess.nl/test/.

However, when I remove the first 2 lines from the /public_html/test/.htaccess it seems to work perfect.
Options +FollowSymlinks
RewriteEngine On


I don't know why I was using these 2 lines, but it is still strange it's using the lines even i'm not requesting that page.