Solved

.htaccess redirect question

Posted on 2006-10-26
12
301 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Apache to Lighttpd 9 63
Php Remote Files 13 56
XAMPP 3 44
Alias for "domain to path" translation instead of VirtualHost on Apache 3 44
In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

16 Experts available now in Live!

Get 1:1 Help Now