Forum Moderators: phranque

Message Too Old, No Replies

Multiple domains on the same server.

Issue with .httaccess rewrite engine

         

Ragatokk

9:58 am on Mar 15, 2016 (gmt 0)

10+ Year Member



I have enabled the rewrite engine in apache.

This is my .httaccess

#to disable directory browsing
Options All -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} nordicreservation.com$ [NC]
RewriteCond %{REQUEST_URI} !^/nordicreservation/.*$
RewriteRule ^(.*)$ /nordicreservation/$1 [L]

RewriteCond %{HTTP_HOST} hjemmedatahjelpen.no$ [NC]
RewriteCond %{REQUEST_URI} !^/hjemmedatahjelpen/.*$
RewriteRule ^(.*)$ /hjemmedatahjelpen/$1 [L]
When I try to resolve hjemedatahjelpen.no I get the index of nordicreservation, and when I try to resolve nordicreservation.com I get ERR_NAME_NOT_RESOLVED.


Any ideas on what I should do to fix this would be much apriciated.

This is where I read about it [enkognedo.com...]

Hav also tried this, but now both domains resolve the root/nordicreservation/index.php


RewriteEngine on
#========================================================================
# FIRST Handle the http requests first before removing the additional url junk
#========================================================================
#rule for hjemmedatahjelpen.no to link to hjemmedatahjelpenfolder directory
RewriteCond %{HTTP_HOST} ^(www.)?hjemmedatahjelpen.no$
RewriteCond %{REQUEST_URI} !^/hjemmedatahjelpen/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /hjemmedatahjelpen/$1
#rule for nordicreservation.com to link to nordicreservationfolder directory. Its the same as above just with nordicreservation URL and subfolder
RewriteCond %{HTTP_HOST} ^(www.)?nordicreservation.com$
RewriteCond %{REQUEST_URI} !^/nordicreservation/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /nordicreservation/$1

#==========================================================
# SECOND Remove the additional url junk once the new url is loaded
#==========================================================
#rule for hjemmedatahjelpen url rewrite to remove /hjemmedatahjelpen/index.php from the URL
RewriteCond %{HTTP_HOST} ^(www.)?hjemmedatahjelpen.no$
RewriteRule ^(/)?$ hjemmedatahjelpen/index.php
#rule for nordicreservation url rewrite to remove /nordicreservation/index.php from the URL. Again its the same as above just with the nordicreservation URL and sub folder info.
RewriteCond %{HTTP_HOST} ^(www.)?nordicreservation.com$
RewriteRule ^(/)?$ nordicreservation/index.php

Ref: [stackoverflow.com...]

lucy24

5:40 pm on Mar 24, 2016 (gmt 0)

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



Ragatokk, are you out there? Your question somehow fell between the "list unread posts" crack, so let us know if you're still having a problem.

:: waving merrily from one Norwegian to another ::

Ragatokk

6:48 pm on Mar 24, 2016 (gmt 0)

10+ Year Member



Yeah, It is sadly still unresolved.

:: waving back ::

lucy24

7:36 pm on Mar 24, 2016 (gmt 0)

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



OK, let's go back to the beginning. In English* what are you trying to do? The bits with
RewriteCond %{HTTP_HOST} nordicreservation.com$ [NC]
RewriteCond %{REQUEST_URI} !^/nordicreservation/.*$
make it look as if the same text can occur twice. Is this about subdirectories for addon domains, where "example.com/blahblah/" = "blahblah.com/" = "blahblah.example.com" ?

Note that you are not supposed to name your own domain in posts. This is a general WebmasterWorld principle but it goes double in the Apache subforum because of auto-linking. So let's call one of them example.com and the other one example.no

When I try to resolve hjemedatahjelpen.no I get the index of nordicreservation, and when I try to resolve nordicreservation.com I get ERR_NAME_NOT_RESOLVED.

You refer to htaccess, so I assume you're on shared hosting. What's the (physical) directory structure for the two domains?


* I mean, ahem, English as opposed to Apache, not English as opposed to some other human language ;)

topr8

9:37 pm on Mar 24, 2016 (gmt 0)

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



just checking ... you say

httaccess with a DOUBLE 't' ... i hope your file is named .htaccess SINGLE 't'

also slightly OT but if this is your own server or even virtual server you should not enable .htaccess, it is much more efficient to write all your rules directly into the .config file (probably within virtual hosts if you have multiple domains)

Ragatokk

10:37 pm on Mar 24, 2016 (gmt 0)

10+ Year Member



It is .htaccess
Sorry for the insane amount of spelling errors I made.
I am useing wamp on my desktop. I would like to resolve this trough .htaccess if possible.

Directory:
http://i.imgur.com/ZM82URK.png

Ragatokk

10:47 pm on Mar 24, 2016 (gmt 0)

10+ Year Member



What I am trying to do is refer:
www.example1.com to www/example1.index
www.example1.com/hi to www/example1/hi
www.example1.com/pictures to www/example1/pictures.index

and

www.example2.com to www/example2.index
www.example2.com/hi to www/example2/hi.php
www.example2.com/pictures to www/example2/pictures.index

(for example haveing to use www.example.com/pictures/index to refer to www/example/pictures.index would also work, but would be more clunky)

lucy24

1:22 am on Mar 25, 2016 (gmt 0)

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



Forms like www/example1/etcetera aren't really URLs, so you can't redirect to them. If you're trying to use filepaths as such in htaccess (or even in a <Directory> section in config), the bad news is that it can't be done, because there's an implied [PT] flag. You'll have to put your rules in the config file.

Granted, htaccess is a lot easier, because you don't have to keep restarting the server. Even a local MAMP/WAMP takes a little while, and it gets annoying. But some things simply cannot be done any other way. WAMP doesn't care that it's all happening on your personal hard drive; it only cares about Apache.

I don't know exactly how WAMP works. I know that in MAMP if you want to run multiple sites locally, you can either pay for the fancy version which I really intend to do one of these days, honest, or you can fiddle with the vhosts file (or <VirtualHost> envelope, depending) and also your computer's own hosts file. (Don't ask me where it lives, or how to edit it, on Windows. It's traumatic enough on the Mac.) On my system, I call them all "local",* like www.example1.local, www.example2.local and so on.


* And I really hope ".local" never gains wide use as a TLD, or I'm sunk :)

Ragatokk

5:19 pm on Mar 25, 2016 (gmt 0)

10+ Year Member



www/example1/whatever is a directory path not a url...
So I should have written www\examle1\whatever... sorry...

lucy24

7:13 pm on Mar 25, 2016 (gmt 0)

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



Does Apache even recognize backslashes? I wouldn't have thought so, since the backslash is the ordinary "escape" character in Regular Expressions.

But the short version is: It really looks as if you're trying to do something in htaccess that can only be done in config. The fact that it's all happening locally makes no difference to Apache.

Ragatokk

11:02 pm on Mar 25, 2016 (gmt 0)

10+ Year Member



I do not know, but what is used is "RewriteCond %{REQUEST_URI} !^/example/"

Ragatokk

4:14 pm on Mar 31, 2016 (gmt 0)

10+ Year Member



Should I bump? Did you give up? Does nobody know the answer?

lucy24

8:07 pm on Mar 31, 2016 (gmt 0)

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



Sit tight. We're going to get a second opinion although not, regrettably, from a second Norwegian.

whitespace

8:51 am on Apr 1, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



From what I understand (from reading the first half of the thread), this sounds perfectly feasible in .htaccess. You are internally rewriting all requests to a particular domain to a subdirectory of that domain. This does assume that all these additional domains point to the same document root (the parent folder: "/www/" by the looks), not the subdirectory. (So in that sense they are more like cPanel's "parked" domains, rather than an "addon" domain. Although if you are developing this locally on a WAMP server, then the terms "parked" and "addon" don't apply in quite the same way.)

This also assumes that "www.example1.com/example1/" is accessible.

when I try to resolve nordicreservation.com I get ERR_NAME_NOT_RESOLVED


However, if this isn't even resolving then that would seem to be your problem?! Is your local DNS/HOSTS file and VirtualHost configured correctly?

www.example1.com to www/example1.index
www.example1.com/hi to www/example1/hi
www.example1.com/pictures to www/example1/pictures.index


Well, I thought I was understanding until I saw this. Where do the ".index" file extensions come from? "www.example1.com/pictures" would need to be rewritten to "www.example1.com/example1/pictures" - which would map to the filesystem path "/www/example1/pictures" (because the document root for "www.example1.com" is "/www/" - ?).

Just stepping back for a moment... what is the reason for doing this in the first place? (Just wondering if mod_rewrite is in fact required at all?)

whitespace

8:57 am on Apr 1, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



> www/example1/whatever is a directory path not a url...
> So I should have written www\examle1\whatever... sorry...

Does Apache even recognize backslashes?


Need to use (forward) slashes throughout the Apache config to refer to filesystem paths, even on Windows.

Ragatokk

9:24 am on Apr 1, 2016 (gmt 0)

10+ Year Member



Whitespace, thanks for taking a look trough this, It does resolve for me when I try to connect, so I find it wierd that it does not resolve for you.
(regardless of what url I use I get refered to the www/nordicreservation/index.php)

whitespace

11:39 am on Apr 1, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



It does resolve for me when I try to connect, so I find it wierd that it does not resolve for you


I was just quoting what you stated in your initial post. (I hadn't even tried to access the sites myself. Since you are "useing wamp on [your] desktop" it is reasonable to assume this is in local development only and not publically available.)

However, if this should be public, then there does seem to be something awry with the DNS... "nordicreservation.com" does not resolve for me, but "www.nordicreservation.com" does. And both appear to resolve to different IP addresses?

Hav also tried this, but now both domains resolve the root/nordicreservation/index.php


Again, I assume this must be "local development", or maybe things have just changed since then? Because "publically" they don't resolve to the same place (as mentioned above, different IP addresses). However, they appear to display the same content because one contains the other in a frame ("framed forwarding"). (?)

Ragatokk

11:59 am on Apr 1, 2016 (gmt 0)

10+ Year Member



Ahh... I think I know what the issue is then, the dude that wanted me to have his site on my ip forwarded it with framed forwarding... and that is why both hitt the www.nordicreservation.com

Thanks allot for telling me that as the only device I have easy acces to thats not on this network is my phone...

Ragatokk

12:04 pm on Apr 1, 2016 (gmt 0)

10+ Year Member



I have a small question btw, what is the diffrence between thse two:
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Again, thankyou for helping out :)

Sorry for making this so hard on you guys.

whitespace

1:59 pm on Apr 1, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month




RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^\.]+)$ $1.php [NC,L]


The first one matches a URL that consists of a single path segment (the URL must end in a trailing slash, but this is excluded from the captured group) and internally rewrites this by appending a ".php" extension. Rewriting then continues (since no L flag). So, a request for "example.com/something/" would be rewritten to "example.com/something.php".

The second rule matches URLs that don't already have a file extension and internally rewrites this by appending a ".php" extension. The current phase of rewriting then stops (L flag). The NC flag is superfluous. So, a request for "example.com/something" would be rewritten to "example.com/something.php". Note that this will also match multiple path segments, ie. "example.com/path/to/file" would be rewritten to "example.com/path/to/file.php".

It looks like these two rules should be used together.

lucy24

8:25 pm on Apr 1, 2016 (gmt 0)

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



[^\.]

Incidentally-- a tiny point-- you don't need to escape periods inside grouping brackets. It won't do any harm, but it isn't necessary.