LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 10-05-2008, 11:51 AM   #1
scls19fr
LQ Newbie
 
Registered: Aug 2008
Posts: 6

Rep: Reputation: 0
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
 
Old 10-05-2008, 12:28 PM   #2
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 561

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

Rewrite /* http://newname.mydomain.com
 
Old 10-05-2008, 12:39 PM   #3
richardfranks
LQ Newbie
 
Registered: May 2005
Location: England
Posts: 10

Rep: Reputation: 0
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
 
Old 10-05-2008, 03:38 PM   #4
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 561

Rep: Reputation: 58
Sorry but I made a mistake, its not Rewrite /* its RedirectMatch /*
 
Old 10-05-2008, 11:04 PM   #5
scls19fr
LQ Newbie
 
Registered: Aug 2008
Posts: 6

Original Poster
Rep: Reputation: 0
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.
 
Old 10-05-2008, 11:40 PM   #6
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
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.
 
Old 10-05-2008, 11:56 PM   #7
scls19fr
LQ Newbie
 
Registered: Aug 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks
I'll put the RedirectMatch in the .htaccess
 
  


Reply


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
URL Rewriting mrpraveen.p Linux - Newbie 1 06-03-2008 07:07 AM
URL Rewriting getmeontop Linux - Newbie 1 04-02-2008 02:12 AM
url rewriting in localhost pamount Red Hat 0 01-08-2008 08:10 PM
.htaccess domain / url forwarding max_tcs Linux - Software 1 12-17-2007 10:40 AM
Mod REWRITE url rewriting gabsik Linux - Networking 1 09-29-2006 05:24 AM


All times are GMT -5. The time now is 01:19 AM.

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