LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   URL rewriting for sub-domain (https://www.linuxquestions.org/questions/linux-server-73/url-rewriting-for-sub-domain-674376/)

scls19fr 10-05-2008 11:51 AM

URL rewriting for sub-domain
 
Hello,

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

I would like that when a user write
http://myapp.mydomain.com
the url automatically change (in the browser)
to http://newname.mydomain.com
because I'd prefer users use newname instead of
myapp.

What's the best way to do this ?

Kind regards

Sebastien

robertjinx 10-05-2008 12:28 PM

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

Rewrite /* http://newname.mydomain.com

richardfranks 10-05-2008 12:39 PM

You could also do this in PHP

PHP Code:

if ($_SERVER['SERVER_NAME'] == 'myapp.mydomain.com') {
    
header('Location: http://newname.mydomain.com' $_SERVER['REQUEST_URI']);


at the very top of your PHP app

robertjinx 10-05-2008 03:38 PM

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

scls19fr 10-05-2008 11:04 PM

Thanks
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-05-2008 11:40 PM

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-05-2008 11:56 PM

Thanks
I'll put the RedirectMatch in the .htaccess


All times are GMT -5. The time now is 12:15 PM.