LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Need help about redirect of apache! (https://www.linuxquestions.org/questions/linux-server-73/need-help-about-redirect-of-apache-738033/)

jefix 07-06-2009 06:14 AM

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.

your_shadow03 07-06-2009 06:24 AM

http://www.yolinux.com/TUTORIALS/ApacheRedirect.html

jefix 07-06-2009 06:38 AM

Quote:

Originally Posted by your_shadow03 (Post 3598323)

But when access http://domain1/index.php?something, not redicect?

this cannot be done..

your_shadow03 07-06-2009 06:44 AM

Have you provided the complete path to the page after which you trying to redirect?
It seems you are not providing the complete path.

jefix 07-06-2009 06:49 AM

Quote:

Originally Posted by your_shadow03 (Post 3598360)
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..

bathory 07-06-2009 07:17 AM

You have to use mod_rewrite in order to be able to redirect such URLs and not Redirect
Code:

RewriteRule  ^(.+)          http://domain2/$1
Regards

jefix 07-06-2009 07:27 AM

Quote:

Originally Posted by bathory (Post 3598397)
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...

sleddog 07-06-2009 07:29 AM

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;



bathory 07-06-2009 07:35 AM

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


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