Apache (MySQL, PHP) redirect

38 views
Skip to first unread message

Andrew Brown

unread,
Dec 8, 2009, 2:51:17 AM12/8/09
to Web Authoring
I need to redirect

http://c18.net/c18/c18_pages.php?nom=c18_publications

to

http://c18.net/18/p.php?nom=p_toutes

and tried in .htaccess

<IfModule mod_alias.c>
[lots of other redirections]
RedirectMatch .*c18_publications http://c18.net/18/p.php?nom=p_toutes
[lots of other redirections]
</IfModule>

which does nothing. There are discussions all over the web on how to
redirect ? urls, and none of the solutions proposed seem to work. Is
there a solution? Getting a bit desperate here...

AB

Jonathan Lundell

unread,
Dec 8, 2009, 11:58:42 AM12/8/09
to web-au...@googlegroups.com
I think you want mod_rewrite, not mod_alias. Or is that not an option?

Bill Hernandez

unread,
Dec 8, 2009, 11:59:27 AM12/8/09
to web-au...@googlegroups.com
Andy,

# FILEPATH : /c18/.htaccess
RewriteEngine On

# test RewriteCond %{HTTP_HOST} USING localhost
# test RewriteRule using plain google

# RewriteCond %{HTTP_HOST} ^(www\.)?localhost
# RewriteCond %{QUERY_STRING} ^nom=c18_publications
# RewriteRule /* http://www.google.com? [R,L]
# RewriteRule /* http://c18.net/18/p.php?nom=p_toutes [R,L]

RewriteCond %{HTTP_HOST} ^(www\.)?c18.net
RewriteCond %{QUERY_STRING} ^nom=c18_publications
RewriteRule /* http://c18.net/18/p.php?nom=p_toutes [R,L]


This '. htaccess ' file worked fine for me...

Best Regards,

Bill Hernandez
Plano, Texas
> --
>
> You received this message because you are subscribed to the Google Groups "Web Authoring" group.
> To post to this group, send email to web-au...@googlegroups.com.
> To unsubscribe from this group, send email to web-authorin...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/web-authoring?hl=en.
>
>
>

Bill Hernandez

unread,
Dec 8, 2009, 11:56:59 AM12/8/09
to web-au...@googlegroups.com
Andy,

RewriteEngine On

# test RewriteCond %{HTTP_HOST} USING localhost
# test RewriteRule using plain google

# RewriteCond %{HTTP_HOST} ^(www\.)?localhost
# RewriteCond %{QUERY_STRING} ^nom=c18_publications
# RewriteRule /* http://www.google.com? [R,L]

RewriteCond %{HTTP_HOST} ^(www\.)?c18.net
RewriteCond %{QUERY_STRING} ^nom=c18_publications
RewriteRule /* http://c18.net/18/p.php?nom=p_toutes [R,L]

This worked fine for me...

Best Regards,

Bill Hernandez
Plano, Texas

On Dec 8, 2009, at 1:51 AM, Andrew Brown wrote:

Bill Hernandez

unread,
Dec 8, 2009, 12:26:41 PM12/8/09
to web-au...@googlegroups.com
Andy,

This is more complete along with some resources...

# --+---------+---------+---------+---------+---------+---------+---------+
# [4321] ( BEGIN ) PROBLEM STATEMENT
# --+---------+---------+---------+---------+---------+---------+---------+
# From: Andrew Brown <andrew...@c18.net>
# Subject: Apache (MySQL, PHP) redirect
# Date: December 8, 2009 1:51:17 AM CST
# To: Web Authoring <web-au...@googlegroups.com>
# Reply-To: web-au...@googlegroups.com
#
# I need to redirect
#
# http://c18.net/c18/c18_pages.php?nom=c18_publications
#
# to
#
# http://c18.net/18/p.php?nom=p_toutes
#
# and tried in .htaccess
#
# <IfModule mod_alias.c>
# [lots of other redirections]
# RedirectMatch .*c18_publications http://c18.net/18/p.php?nom=p_toutes
# [lots of other redirections]
# </IfModule>
#
# which does nothing. There are discussions all over the web on how to
# redirect ? urls, and none of the solutions proposed seem to work. Is
# there a solution? Getting a bit desperate here...
#
# AB
#
# --+---------+---------+---------+---------+---------+---------+---------+
# [4322] ( BEGIN ) ACKNOWLEDGEMENT
# --+---------+---------+---------+---------+---------+---------+---------+
# Andy,
#
# This uses mod_rewrite, to test if you have mod_rewrite enabled, look at the references below.
#
# This '. htaccess ' file worked fine for me...
#
# Best Regards,
#
# Bill Hernandez
# Plano, Texas

# --+---------+---------+---------+---------+---------+---------+---------+
# [4323] ( BEGIN ) SOLUTION REFERENCES
# --+---------+---------+---------+---------+---------+---------+---------+

# REFERENCE : http://wiki.apache.org/httpd/RewriteQueryString
# REFERENCE :http://www.wallpaperama.com/forums/how-to-test-check-if-mod-rewrite-is-enabled-t40.html

# --+---------+---------+---------+---------+---------+---------+---------+
# [4324] ( BEGIN ) FILEPATH : /c18/.htaccess
# --+---------+---------+---------+---------+---------+---------+---------+
RewriteEngine On

# --+---------+---------+---------+---------+---------+---------+---------+
# TEST USING LOCALHOST
# --+---------+---------+---------+---------+---------+---------+---------+
# http://localhost/c18/c18_pages.php?nom=c18_publications

# --+---------+---------+---------+---------+---------+---------+---------+
# REDIRECT TO google
# --+---------+---------+---------+---------+---------+---------+---------+
# RewriteCond %{HTTP_HOST} ^(www\.)?localhost
# RewriteCond %{QUERY_STRING} ^nom=c18_publications
# RewriteRule /* http://www.google.com? [R,L]

# --+---------+---------+---------+---------+---------+---------+---------+
# REDIRECT TO THE REAL PAGE
# --+---------+---------+---------+---------+---------+---------+---------+
# RewriteCond %{HTTP_HOST} ^(www\.)?localhost
# RewriteCond %{QUERY_STRING} ^nom=c18_publications
# RewriteRule /* http://c18.net/18/p.php?nom=p_toutes [R,L]

# --+---------+---------+---------+---------+---------+---------+---------+
# NOW FOR THE REAL REDIRECT
# --+---------+---------+---------+---------+---------+---------+---------+
RewriteCond %{HTTP_HOST} ^(www\.)?c18.net
RewriteCond %{QUERY_STRING} ^nom=c18_publications
RewriteRule /* http://c18.net/18/p.php?nom=p_toutes [R,L]
# --+---------+---------+---------+---------+---------+---------+---------+
# [4323] ( _END_ ) FILEPATH : /c18/.htaccess
# --+---------+---------+---------+---------+---------+---------+---------+

Andrew Brown

unread,
Dec 9, 2009, 2:00:05 AM12/9/09
to web-au...@googlegroups.com
That does it Bill, many thanks !

It fails ("too many redirects") if what follows nom= does not change,
presumably in that case I could add another RewriteCond %
{QUERY_STRING} line.

AB

On 8 Dec 2009, at 18:26, Bill Hernandez wrote:

> # --+---------+---------+---------+---------+---------+---------
Reply all
Reply to author
Forward
0 new messages