problem with .htaccess

Alles, was den Apache betrifft, kann hier besprochen werden.

problem with .htaccess

Postby koopie66 » 31. October 2014 17:23

Hi

I have the following problem my site:

I have 2 domains: 1 is pointing at the public_html root and the another one is pointing at a directory
so:
www.domain1.com -> public_html
www.domain2.com --> public_html/site2

I use a number of sub directories under site2

This works fine, but when I go to www.domain2.com/subdir (without a trailing slash) it gives me the following URL in Internet Explorer:
www.domain1.com/site2/subdir
When I use a traling slash at the end www.domain2.com/subdir/ the adress is the correct URL.

So I tried to add the following code into my .htaccess in directory site2:

RewriteEngine On
RewriteBase /site2/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.domain2.com/$1/ [L,R=301]

But the result is the same. Can someone help me, since I probably do some thing wrong?

thanks in advance

Hans
koopie66
 
Posts: 2
Joined: 31. October 2014 17:06
Operating System: linux

Re: problem with .htaccess

Postby Nobbie » 31. October 2014 20:10

koopie66 wrote:I have 2 domains: 1 is pointing at the public_html root and the another one is pointing at a directory
so:
www.domain1.com -> public_html
www.domain2.com --> public_html/site2


What do you mean with "pointing"? Apache (and PHP) knows different Options, to assign folders to URLs, but "pointing" is unknown. We need to know exactly, how you realized this. Either via an ALIAS, or via VirtualHosts and DocumentRoot, or via Redirection in .htaccess, or Redirection via PHP Script (Location Header) etc. pp.!?
Nobbie
 
Posts: 8759
Joined: 09. March 2008 13:04

Re: problem with .htaccess

Postby koopie66 » 01. November 2014 15:25

Ok I will try to clarify:

I have 2 domains on a hosted environment

my first domain (domain1) is referring to the root ie. public_html. If I type in URL www.domain1.com in my browser I correctly see the index page in the folder. My second domain. www.domain2.com is referring to sub directory public_html/site2. If I type the URL www.domain2.com in my browser I see correctly the index page in this folder. This is done via an redirection entry in my .htaccess in the directory public_html.
.htacesss
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.) ?domain2.com$ [NC]
RewriteCond %{REQUEST_URI} !site2/ [NC]
RewriteRule ^(.*)$ /site2/$1 [L]


This works fine, but when I type in the URL www.domain2.com/subdir (without a trailing slash) it gives me the following URL in Internet Explorer:
www.domain1.com/site2/subdir

When I use a traling slash at the end www.domain2.com/subdir/ the adress is the correct URL.

So I tried to add the following code into my .htaccess in directory site2:

RewriteEngine On
RewriteBase /site2/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.domain2.com/$1/ [L,R=301]
koopie66
 
Posts: 2
Joined: 31. October 2014 17:06
Operating System: linux

Re: problem with .htaccess

Postby Nobbie » 02. November 2014 18:06

koopie66 wrote:my first domain (domain1) is referring to the root ie. public_html.


Still the same problem, there is no "referring" in Apache context (exactly as there is no "pointing"). As i already said, there is "DocumentRoot", or ALIAS or similar - but not "pointing" and not "referring".

koopie66 wrote:This is done via an redirection entry in my .htaccess in the directory public_html.


Why did you do so?? Why dont you simply assign the appropriate DocumentRoot? The "stacking" of URL rewrites may become very difficult to handle (and actually your are confused already by this).
Nobbie
 
Posts: 8759
Joined: 09. March 2008 13:04


Return to Apache

Who is online

Users browsing this forum: No registered users and 3 guests