Forum Moderators: phranque
So, I am trying to add a redirect to my .htaccess to redirect any hits on the file (imagedisplay.php) to the gallery root.
I tried the following as a simple redirect;
RedirectMatch permanent ^/coppermine/displayimage.php$ /coppermine/
However, this also redirects all requests for actual images, eg:
..../coppermine/displayimage.php?album=random&cat=17&pos=-455
Therefore, my question is how to add the redirect ot the .htaccess file so that it redirects ONLY those requests that ARE NOT genuine and DO NOT end in; ?album=random&cat=XX&pos=-#*$!
Thanks for any help.
However, I'm afraid my knowledge of Apache isn't that good sorry.
Although, referring to current examples, I'm guessing it would be something like (?):
RewriteCond %{HTTP_HOST} ^mysite.blah/coppermine/displayimage.php$ [OR]
RewriteCond %{HTTP_HOST} ^www.mysite.blah/coppermine/displayimage.php$
RewriteRule ^(.*)$ http://www.mysite.blah/coppermine/ [R=301,L]
Thank you.
Specific questions are most welcome, but please read the docs for the basics.
Our forum charter (link at top left above) also contains links to several useful resources.
Thanks,
Jim
1.
RewriteEngine on
RewriteCond %{QUERY_STRING} ^/coppermine/displayimage.php$. [or]
RewriteCond %{QUERY_STRING} ^/coppermine/thumbnails.php$.
RewriteRule ^$ /coppermine/? [R=301,L]
2.
RewriteEngine on
RewriteCond %{query_string} ^/coppermine/displayimage.php$
RewriteRule ^$ /coppermine/ [R=301,L]
To no avail.... yet....
# If NOT valid query
RewriteCond %{QUERY_STRING} !^album=[^&]+&cat=[^&]+&pos=.+$
# redirect from /coppermine/displayimage.php to /coppermine/
RewriteRule ^coppermine/displayimage\.php$ http://www.example.com/coppermine/ [R=302,L]
Jim
The file resides in my root .htaccess file and the code is at the top of the file, just below my error page settings.
The exact code reads:
RewriteEngine On
RewriteCond %{QUERY_STRING} !^album=[^&]+&cat=[^&]+&pos=.+$
RewriteRule ^http://www.mysite.blah/coppermine/displayimage\.php$ http://www.mysite.blah/coppermine/ [R=302,L] (mysite.blah is of course replaced with my correct domain)
I've just tried the above code again and still no luck.
Thank you for your time and patience Jim and sorry to trouble you.
RewriteEngine on
RewriteCond %{QUERY_STRING} !^album=[^&]+&cat=[^&]+&pos=.+$
RewriteRule ^coppermine/displayimage\.php$ http://www.example.com/coppermine/ [R=302,L]
Be aware that one single character out of place in mod_rewrite can completely break your server; One little typo can cause a problem you may not find for months -- after your search rankings have been devastated. Make no changes without reading the documentation, reviewing the examples, and thoroughly understanding what those changes mean. There is no "freestyle" coding in .htaccess -- The code is lean and mean and totally unforgiving of errors.
Jim
See also: [webmasterworld.com...]