We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Directory Issue with Apache

crsfs
crsfs asked
on
Medium Priority
215 Views
Last Modified: 2012-05-06
I have a website that I can access by going to http://www.mysite.com/mysite/index.html.

How can I fake the server into thinking that http://www.mysite.com/mysite/index.html is acutally http://www.mysite.com/index.html, without moving any of the code.

I'm using apache.
Comment
Watch Question

Top Expert 2008

Commented:
You'll need a RewriteRule which rewrites your file. But be aware that relative references in your HTML source code may be broken since you're now in the root folder. Or do you like to rewrite everything to /mysite/?
#/.htaccess, i.e. in the URL-path root
RewriteEngine on
RewriteRule ^(index\.html)$ /mysite/$1 [L]

Open in new window

Author

Commented:
It's a full site there, so we'd probably have to change all the references.  Is this rewriting each file as it's read or is it just modifying the full url?

So in the example http://www.mysite.com/mysite/level2/index.html, etc. would be accessible from http://www.mysite.com/level2/index.html.

From other things I've looked at, it looks like this may be do-able with VirtualHosts in http.conf?

Author

Commented:
sorry apache2.conf, not http.conf.
Top Expert 2008

Commented:
> So in the example http://www.mysite.com/mysite/level2/index.html, etc. would be accessible from http://www.mysite.com/level2/index.html.

No, not yet.

Trying to figure out the best solution...:

Are there other files/folders present (e.g. /foo) which should not go into /mysite/?

> From other things I've looked at, it looks like this may be do-able with VirtualHosts in http.conf?

If you have a separate domain or subdomain, yes.

(httpd.conf is the standard name in the distribution from apache.org, other distributors have chosen to use another name)

Author

Commented:
Yes, it ends up being kind of a deep structure.  I'd like to access everything in " /mysite/ " as if it were just in " / ".

Essentially, the application that is exposing the content, forces the extra folder, we just want that to disappear.
Top Expert 2008
Commented:
So you can't change the DocumentRoot due to your application?

The following in your apache2.conf (outsite of <directory> etc.) will rewrite everything but mysite into /mysite/ while the path represents the full physical path.
#apache2.conf
RewriteEngine on
RewriteCond $1 !^mysite
RewriteRule ^/(.*) /var/www/mysite/$1 [L]

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks a lot.  I'm new to Apache, and web dev in general, so I assume I'm screwing up some of the terminology.

So, going to http://www.mysite.com will show http://www.mysite.com but will be pulling files from http://www.mysite.com/mysite/  ?
Top Expert 2008

Commented:
Yes, that's an internal rewrite which doesn't change REQUEST_URI but maps the request to another physical path (except if there's some error and /mysite/ was requested to prevent a mapping to /var/www/mysite/mysite/).

Author

Commented:
Great.  Truly a genius.  Thanks for bearing with me as I learn this stuff.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.