Hey ALUG,
I've been fiddling with this RewriteRule in Apache for ages (I did ask an Apache forum but no one answered). I wonder if anyone knows anything about these things?
I want to make old fashioned URLs like: http://www.sara.uea.ac.uk/search_from_listings.php?artist_id=13 redirect to the new ones: http://www.sara.uea.ac.uk/?artist&id=13
I've tried this rewrite rule (and about a million permutations of it):
RewriteRule ^/search_from_listings.php?artist_id=([0-9]+)$ http://www.sara.uea.ac.uk/?artist&id=$1
I've tried escaping all the characters and I've tried all sorts of combinations of flags but it never works.
For some reason this: RewriteRule ^/search_from_listings.php?(.*)$ http://www.sara.uea.ac.uk/$1
matches (though it doesn't do anything useful).
Any ideas?
Cheers, Richard
Hi Richard.
I want to make old fashioned URLs like: http://www.sara.uea.ac.uk/search_from_listings.php?artist_id=13 redirect to the new ones: http://www.sara.uea.ac.uk/?artist&id=13
The new ones have a rather odd format. You're not already using some other rewriterule to translate them or something are you?
I've tried this rewrite rule (and about a million permutations of it):
RewriteRule ^/search_from_listings.php?artist_id=([0-9]+)$ http://www.sara.uea.ac.uk/?artist&id=$1
I don't think you can rewrite urls with querystrings like that. IIUC you need to use rewritecond and %{QUERY_STRING}. Rewriterule doesn't consider the querystring to be part of the URL.
For some reason this: RewriteRule ^/search_from_listings.php?(.*)$ http://www.sara.uea.ac.uk/$1
matches (though it doesn't do anything useful).
That's because it's interpreting the 'p?' as a regular expression meaning zero or one instances of 'p'. Since this is followed by (.*) it'll match anything starting with /search_from_listings.ph.
Hope this is some help,
Joe x
On Mon, 9 May 2005 19:58:49 +0000, "Joe Button" alug2@joebutton.co.uk said:
Hi Richard.
I want to make old fashioned URLs like: http://www.sara.uea.ac.uk/search_from_listings.php?artist_id=13 redirect to the new ones: http://www.sara.uea.ac.uk/?artist&id=13
The new ones have a rather odd format. You're not already using some other rewriterule to translate them or something are you?
Not for those ones, no (I've got several URL schemes supporting different past versions which are all implemented as RewriteRules).
This one works because the main PHP script is called index.php (i.e. is automatically started by Apache in the absence of any other file name) and knows how to read the slightly odd (but short) URL.
I don't think you can rewrite urls with querystrings like that. IIUC you need to use rewritecond and %{QUERY_STRING}. Rewriterule doesn't consider the querystring to be part of the URL.
OK, thanks for the tip. I've managed to get it to work:
RewriteCond %{QUERY_STRING} ^artist_id=([0-9]+)$ RewriteRule ^/search_from_listings.php$ http://www.sara.uea.ac.uk/?artist&id=%1 [L]
Thanks very much for your help!
Richard