Solved

.htaccess redirect question

Posted on 2006-10-26
12
304 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
  • 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
 
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

912 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now