Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 12-28-2011, 07:40 PM   #1
Registered: Sep 2007
Posts: 119

Rep: Reputation: 17
Automatic path (not URL) rewriting with apache?

I'm not sure if this is at all possible, but I would like to automatically rewrite a path whenever a page is requested (through apache). I don't want to actually rewrite the URL, but the absolute path the page is retrieved from.

Let me try to explain that more clearly.

I have a directory on my Linux server, say /var/www which serves as the document root for Apache. So when someone requests, it serves /var/www/somepage.html.

But what I want is that when someone requests, instead of serving /var/www/concepts/clientA/somepage.html, it serves /home/concepts/clientA/somepages.html.

So as soon as the root directory in the url is "concepts", I want it to retrieve the page from the /home/concepts directory.

/homes/concepts/clientA/somepage.html is not directly accessible from the web so I can't use mod-rewrite.

Also, I don't want to create symbolic links for each client because I simply want to create subdirs under the "concepts" directory, and be able to automatically access them over the web.

Hope my question makes any sense.
Old 12-28-2011, 08:16 PM   #2
Registered: Sep 2007
Posts: 119

Original Poster
Rep: Reputation: 17
Sorry, my question above is incomplete (since the easy solution for the above question would be to use the "Alias" directive). Let me try to better explain what I want (it's 2:15am here so bear with me).

My apache directory structure is as follow:

/var/www/htdocs <- apache document root
/var/www/cgi-bin <- cgi-bin script root

In my apache.conf file, I have set

DocumentRoot "/var/www/htdocs"
ServerAlias /cgi-bin/ "/var/www/cgi-bin/"

So when "" is requested, "/var/www/htdocs/somepage.html" is served.
And when "" is requested, "/var/www/cgi-bin/somescript.cgi" is served.

But now I want some special cases:
When "" is requested, "/home/concepts/clientA/htdocs/somepage.html" is served.
When "" is requested, "home/concepts/clientA/cgi-bin/somescript.cgi" is served.

Like I said, I don't want to add a directive for each client. So I don't want this in my apache.conf:

Alias "/concepts/clientA/cgi-bin/" "/home/concepts/clientA/cgi-bin/"
Alias "/concepts/clientA/" "/home/concepts/clientA/htdocs/"
Alias "/concepts/clientB/cgi-bin/" "/home/concepts/clientB/cgi-bin/"
Alias "/concepts/clientB/" "/home/concepts/clientB/htdocs/"

I want something like this:

Alias "/concepts/*/cgi-bin" "/home/concepts/*/cgi-bin/"
Alias "/concepts/*/" "/home/concepts/*/htdocs/"

Hope that makes sense (like I said, it's 2:15am here and I'm tired ).
Old 12-28-2011, 08:51 PM   #3
Registered: Sep 2007
Posts: 119

Original Poster
Rep: Reputation: 17
Got it. Was easier than I thought it would be:

AliasMatch ^/concepts/(.*?)/(.*) /home/concepts/$1/htdocs/$2
ScriptAliasMatch ^/concepts/(.*?)/cgi-bin/(.*) /home/concepts/$1/cgi-bin/$2

Just never knew those two directives existed.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
htaccess url rewriting dazzler20 Programming 1 12-22-2011 01:47 AM
LXer: How I Solved a URL Rewriting Issue with Apache LXer Syndicated Linux News 0 11-19-2011 12:50 PM
URL Rewriting in htaccess hatchnet Linux - General 7 07-05-2010 06:57 PM
URL Rewriting mrpraveen.p Linux - Newbie 1 06-03-2008 08:07 AM
URL Rewriting getmeontop Linux - Newbie 1 04-02-2008 03:12 AM

All times are GMT -5. The time now is 06:14 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration