Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

.htaccess redirect question

Posted on 2006-10-26
12
Medium Priority
?
320 Views
Last Modified: 2010-03-04
I am trying to redirect this page:

/gallery/index.php?list=1 to /gallery1.php

I tried this code in my .htaccess file but it does not work:

Redirect /gallery/index.php?list=1 http://www.sitename.com/gallery1.php

I am fairly sure .htaccess does not understand the “?list=1” part.

Any way around this?
0
Comment
Question by:danomatic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 43

Expert Comment

by:ravenpl
ID: 17817952
Redirect does not work on query strings, so You can only
Redirect /gallery/index.php http://www.sitename.com/gallery1.php

But You caould use mod_rewrite and match against QUERY_STRING
To learn mod_rewrite http://www.google.com/search?q=mod_rewrite+howto
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 17818404
ravenpl is correct - you must use mod_rewrite.  Assuming that mod_rewrite has been compiled into your version of Apache, you'd use something to the effect of the following in your .htaccess file:

RewriteEngine On
RewriteRule ^/gallery/index\.php?list=([0-9]+) http://www.sitename/gallery$1.php
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17818430
> RewriteRule ^/gallery/index\.php?list=([0-9]+) http://www.sitename/gallery$1.php
Wrong! I also pointed out, that during rewrite one have to match against QUERY_STRING. RewriteRule does not take query string into account as well.

RewriteEngine On
RewriteCond %{QUERY_STRING} ^list=([0-9]+)$
RewriteRule ^/gallery/index\.php http://www.sitename/gallery%1.php
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 15

Expert Comment

by:periwinkle
ID: 17818547
One more cup of coffee for me, please - thanks for correcting my mistake!
0
 
LVL 3

Author Comment

by:danomatic
ID: 17820345
ravenpl: I tried your code but it does not work.  What is the "%" in gallery%1.php
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 17820379
danomatic - possibly a typo - try:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^list=([0-9]+)$
RewriteRule ^/gallery/index\.php http://www.sitename/gallery$1.php
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 1200 total points
ID: 17820436
> RewriteRule ^/gallery/index\.php http://www.sitename/gallery$1.php
In such line $1 refers to nothing [as no match with () was done]
But %1 refers to first () match in most recent RewriteCond statement
Refer http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 17821168
thanks, Ravenpl - I'm 0 for 2, and apologize if I've added to any confusion.   As you may have guessed, my experience in mod_rewrite has been a bit, umm, rudimentary at this point.  

danomatic - any more information about what is possibly going wrong in the error_log/access_log that might help ravenpl diagnose the problem?
0
 
LVL 16

Assisted Solution

by:HackneyCab
HackneyCab earned 400 total points
ID: 17821763
The only thing I can see wrong with ravenpl's code is that he's used an absolute path (starts with a forward slash) in the match pattern. And .htaccess doesn't allow such a thing.

Try this to replace that last line of his code:

RewriteRule ^gallery/index\.php$ http://www.sitename/gallery%1.php
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17821882
Right - my typo. Sorry  - I was copy-paste from question :(
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 17821897
And I'll take credit for that mistake, too. Ugh.
0
 
LVL 3

Author Comment

by:danomatic
ID: 17916721
ok, I am still working on this, have not forgotten about it.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question