-   Linux - Server (
-   -   URL rewriting for sub-domain (

scls19fr 10-05-2008 12:51 PM

URL rewriting for sub-domain

I on a Linux server with Apache / PHP.
My PHP app is available at
myapp is a virtal host (pointing
on my server to /var/www/myapp )
I also add a DNS inscription for
so my app is now also available

I would like that when a user write
the url automatically change (in the browser)
because I'd prefer users use newname instead of

What's the best way to do this ?

Kind regards


robertjinx 10-05-2008 01:28 PM

In the virtual host entriy for the myapp you could do this:

Rewrite /*

richardfranks 10-05-2008 01:39 PM

You could also do this in PHP

PHP Code:

if ($_SERVER['SERVER_NAME'] == '') {
header('Location:' $_SERVER['REQUEST_URI']);

at the very top of your PHP app

robertjinx 10-05-2008 04:38 PM

Sorry but I made a mistake, its not Rewrite /* its RedirectMatch /*

scls19fr 10-06-2008 12:04 AM

I prefer not to modify the PHP code because the app has proprietary code.
Is it possible to at the RedirectMatch in a .htaccess at the root of my app.

Mr. C. 10-06-2008 12:40 AM

Yes, you can place RedirectMatch's in your .htaccess files. They act recursively, and can be redefined at a lower level in the directory (web space) tree.

scls19fr 10-06-2008 12:56 AM

I'll put the RedirectMatch in the .htaccess

All times are GMT -5. The time now is 12:11 AM.