Solved

.htaccess redirect question

Posted on 2006-10-26
12
312 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 300 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 100 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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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