LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 07-06-2009, 06:14 AM   #1
jefix
LQ Newbie
 
Registered: Jul 2009
Posts: 4

Rep: Reputation: 0
Need help about redirect of apache!


Hi ,all
How can apache do this:

When access http://domain1/index.php , apache redirect to http://domain2/index.php ?
But when access http://domain1/index.php?something, not redicect?

only use .htaccess.

Thanks.

Last edited by jefix; 07-06-2009 at 06:25 AM.
 
Old 07-06-2009, 06:24 AM   #2
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466
Blog Entries: 6

Rep: Reputation: 51
http://www.yolinux.com/TUTORIALS/ApacheRedirect.html

Last edited by your_shadow03; 07-06-2009 at 06:27 AM.
 
Old 07-06-2009, 06:38 AM   #3
jefix
LQ Newbie
 
Registered: Jul 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by your_shadow03 View Post
But when access http://domain1/index.php?something, not redicect?

this cannot be done..
 
Old 07-06-2009, 06:44 AM   #4
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466
Blog Entries: 6

Rep: Reputation: 51
Have you provided the complete path to the page after which you trying to redirect?
It seems you are not providing the complete path.
 
Old 07-06-2009, 06:49 AM   #5
jefix
LQ Newbie
 
Registered: Jul 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by your_shadow03 View Post
Have you provided the complete path to the page after which you trying to redirect?
It seems you are not providing the complete path.
When access http://domain1/index.php (only this url), redirect to http://domain2/index.php

but when access http://domain1/index.php?something , not redirect.

here something stands for sth like 'key=a'.

In my .htaccess:
RewriteEngine on
RedirectMatch 301 ^/index.php$ http://domain2/index.php

but when I access 'http://domain1/index.php?key=a', it redirects to

http://domain2/index.php too..
 
Old 07-06-2009, 07:17 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,230
Blog Entries: 1

Rep: Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085
You have to use mod_rewrite in order to be able to redirect such URLs and not Redirect
Code:
RewriteRule   ^(.+)          http://domain2/$1
Regards

Last edited by bathory; 07-06-2009 at 07:20 AM.
 
Old 07-06-2009, 07:27 AM   #7
jefix
LQ Newbie
 
Registered: Jul 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bathory View Post
You have to use mod_rewrite in order to be able to redirect such URLs and not Redirect
Code:
RewriteRule   ^(.+)          http://domain2/$1
Regards

I do enabled mod_rewrite.

I use your code, but when I access http://localhost/index.php?key=1
,it goes to domain2 again.

what I want is when access and only access 'http://localhost/index.php', it redirect to 'http://domain2/index.php', any other urls like 'http://localhost/index.php?key=1' ,do not redirect.

Thanks a lot, I've tried all day, almost freak...
 
Old 07-06-2009, 07:29 AM   #8
sleddog
Member
 
Registered: Jan 2002
Location: Labrador, Canada
Distribution: CentOS, Debian
Posts: 182

Rep: Reputation: 35
Or you can do it with PHP by adding something like this to the top of your index.php file on domain1:

PHP Code:
if (!$_GET) {
    
header ('Location: http://domain2/index.php');
    exit;

 
Old 07-06-2009, 07:35 AM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,230
Blog Entries: 1

Rep: Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085Reputation: 2085
You didn't say anything about localhost
Anyway, you have to add a RewriteCond for localhost:
Code:
RewriteCond   %{REQUEST_URI}   ^localhost/index.php$
RewriteRule   ^(.+)          http://domain2/index.php
Note that Redirect (uses mod_alias) is different than mod_rewrite

Last edited by bathory; 07-06-2009 at 08:07 AM.
 
  


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
Apache Redirect Help! Jude Terror Programming 2 04-07-2009 11:47 AM
Apache 2 Redirect kmeyers Linux - Software 4 02-26-2009 07:13 AM
apache redirect mahmoud Linux - Newbie 3 01-13-2009 08:59 PM
redirect in Apache baslemmens Linux - Networking 6 09-02-2004 12:07 PM
apache redirect? fibbi Linux - Software 7 01-30-2004 10:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:10 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration