Apache Virtual Path


 
Thread Tools Search this Thread
Top Forums Web Development Apache Virtual Path
# 1  
Old 06-11-2013
Apache Virtual Path

Say there is a certain path I wish to always load the same page. So if they go to somesite.com/a/b/c, it always goes to myscript.php and fed a/b/c as a server variable.

I'm fairly sure this is possible but cannot remember the term it's called, and so cannot find it in web searches or documentation. Any hints please?
# 2  
Old 06-11-2013
You are looking for mod_rewrite and the rewrite engine.

You probably need something like (from memory):

Code:
RewriteRule (.*) myscript.php?id=$1

# 3  
Old 06-11-2013
I'm not so sure. I don't think the original name would be preserved, and I need that.
# 4  
Old 06-12-2013
Hm, I think, it does. I put a script myscript.php in the document root:

Code:
<?php
    echo 'myscript.php running with id = ' . $_GET['id'];
?>

In the apache config I added:

Code:
<Directory /var/www/html>
     RewriteEngine On
     RewriteCond %{REQUEST_URI} !^/myscript.php.*
     RewriteRule (.*) myscript.php?id=$1 [L]
</Directory>

When you enter the URL http://servername/a/b/c in the browser, the output looks like:

Code:
myscript.php running with id = a/b/c

# 5  
Old 06-12-2013
[edit] Actually, this does not work.

This changes the URL the client goes to, it redirects and changes the address bar. I do not want that. I just want anything beneath a certain folder to all call the same script.

Last edited by Corona688; 06-12-2013 at 12:11 PM..
# 6  
Old 06-12-2013
In my test environment (CentOS 6.4, Apache 2.2, PHP 5.3.3) it does not change the URL in the address bar of the browser. And in my opinion, this is expected, because it is not a redirect but a rewrite within the webserver.

If it does for you, there must be some other difference between our environments.
# 7  
Old 06-13-2013
I'm not sure why some rewrite rules redirect and some don't, but I fiddled until I got it working. Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Apache Virtual host issue

Hello, I am facing a very strange issue while setting a virtual host on apache to setup multiple websites using separate IPs. Virtual host is setup but when i am browsing the website it display content under /var/www/html and displaying site1 and site2 folder instead of access the content... (2 Replies)
Discussion started by: sunnysthakur
2 Replies

2. Web Development

Problems with Apache Virtual Host

I am attempting to add virtual hosts to an apache web server, which has this current configuration: <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None ... (27 Replies)
Discussion started by: Corona688
27 Replies

3. Red Hat

Apache question - virtual host related

Hi folks, I recently read about Apache virtual host and was able to configure that as well. I used name based virtual host (lets say http://vhost1.example.com) and it worked just fine. Then I configured another named based virtual host on same apache server (lets say http://vhost2.example.com)... (2 Replies)
Discussion started by: freebird8z
2 Replies

4. Red Hat

Virtual Host Apache

Hi, I have set up the following virtual host but it cannot find the URL? Apache is running fine and I have disabled iptables. Within the document root I have the following file index.html displaying a sample text message. Any ideas what my problem might be? httpd.conf: ... (2 Replies)
Discussion started by: Duffs22
2 Replies

5. Web Development

Apache Virtual URL

Hi All, i'am facing a problem with urls that don't have a filestructure under DocumentRoot. A URL like http://mydomain.com/applicationrew/Structure1/Structure2/some?parameter=key&parameter1=key1 Should be rewritet to something else. Now i defined a Location like <Location ~... (3 Replies)
Discussion started by: wuschelz
3 Replies

6. Linux

Apache Virtual Server Help

Hi I am trying to configure virtual host on apache and I am running into a problem where the server defaults to the default location and I cannot get apache to pull from the second server. I have configured 2 files in vhosts.d folder I have added NameVirtualHost *.80 to the httpd.conf I have... (0 Replies)
Discussion started by: ratnamg
0 Replies

7. UNIX for Dummies Questions & Answers

Application & Virtual hosts in Apache

Folks; I need help knowing how to add an application to existing Virtual host on Apache. here's the details: I have a virtual host file (Based on IP address) for Apache and is configured to run application inside it. How can i add another application to the same virtual host based on the same IP... (0 Replies)
Discussion started by: moe2266
0 Replies

8. UNIX for Dummies Questions & Answers

Apache not logging virtual domain

A client has asked us to set up a different domain (as an alias for their site) which they could use on certain marketing material and hence measure the campaign's effectiveness. We've set it up and it all seems to be working fine except that the access log file for the new domain is stuck at zero... (2 Replies)
Discussion started by: fire>ant>
2 Replies

9. UNIX for Advanced & Expert Users

Apache 2 Virtual Hosts not resolving

Hey all, I'm having some apache problems. I've installed apache countless times on FreeBSD. However, I'm having some problems and I could use some help. Here is my system info: FreeBSD 5.2.1 Apache 2.0.51 (/usr/local/apache2), doc root (/www symlink to /var/www) PHP 5.0.1 (/usr/local/php)... (2 Replies)
Discussion started by: ezekiel61
2 Replies

10. UNIX for Dummies Questions & Answers

Apache virtual host

Would this be the correct entry for Apache to answer on the IP 129.250.242.126 if the servers IP is 129.250.242.125? Are any other changes necessary to get Apache to answer this IP for web traffic? < VirtualHost 129.250.242.126> ServerName www.my_domain.com ServerAdmin admin@my_domain.com... (4 Replies)
Discussion started by: 98_1LE
4 Replies
Login or Register to Ask a Question