[htaccess] Domain Pointers

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

[htaccess] Domain Pointers

Post by Gen-ik »

Hi guys!

It has been a while since I last visted.. looks like a few things have changed around here. :) Anyway, I need some help with a bit of htaccess that I can not for the life get to work properly.

I have a domain name pointing to the root directory of my server, and I'm currently checking the HOST_NAME using PHP and redirecting it to the correct folder where the site contents are stored.

For example, mydomain.com is pointing to myserver.com which checks the HOST_NAME and directs the visitor to mydomain.com/website/

What I am trying to do is create a bit of htacess code that will remove the /website/ bit from the URL. For example,

mydomain.com/website/ would actually be displayed in the browser as mydomain.com/
and mydomain.com/website/news/ would be displayed as mydomain.com/news/

I don't have access to the .conf file on the server otherwise that would be the easiest way to sort this out.

Hope that makes sense. ;)


PS. Code so far...

Code: Select all

RewriteEngine on
RewriteBase /
RewriteCond %{HOST_NAME} ^www.mydomain.com$ їOR]
RewriteCond %{HOST_NAME} $mydomain.com$
RewriteCond ${REQUEST_URI} !^/website/(.*)$
RewriteRule ^(.*)$ /website/$1 їL]
...I think that's right anyway. I don't have the actual .htaccess file handy at the moment.

If anyone knows how to do this I would be very happy. :D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

was playing around with this sort of thing this morning..

Code: Select all

RewriteEngine on
RewriteCond %{SERVER_NAME} ^(www\.)?mydomain\.com$
RewriteCond %{REQUEST_URI} !^/website/
RewriteRule ^(.*) /website$1 їL]
I think...
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Cheers mate. Looks like I was on the right track then.

One thing I did notice was that I could just type "mydomain.com/website/" into the browser location and it would still go there.. ie, it didn't change to "mydomain.com/".

I found a way around that though with this...

Code: Select all

if(stristr($_SERVER["REQUEST_URI"], "/website/") !== false) {
  $split = explode("/website/", $_SERVER["REQUEST_URI"]);
  header("location:/{$split[1]}");
  exit;
}
...and it all seems to be working fine now.
Post Reply