Solved

.htaccess redirect question

Posted on 2006-10-26
12
307 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Maintain Parameters on URL throughout Site (PHP) 6 38
Trying to connect the LDAP over SSL 38 287
XAMPP 14 44
Updating PHP in Windows Server 2012 r2 22 161
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
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 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 …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

777 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