sw0o0sh Posted June 28, 2010 Share Posted June 28, 2010 I've been working on some URL rewrites, they seem to be going smoothly so far. However, I'm encountering one issue with <form>s that are GET type. I would like to redirect these to the appropriate URL format.. but I can't quite figure out how to write the redirect. Basically, I need highscores.php?user=x to be transfered to highscores/user/x, but this code is giving me problems (not redirecting at all) RewriteRule ^highscores.php?user=([^/]+)$ highscores/user/$1 [R=302,NC] Quote Link to comment https://forums.phpfreaks.com/topic/206066-another-redirect-issue-xa-to-xa/ Share on other sites More sharing options...
cags Posted June 28, 2010 Share Posted June 28, 2010 You appear to be using the process backwards. Your links in your site should really be of the format highscores/user/20, this should then be rewritten to the 'ugly' format, not vice versa. Incidentally a RewriteRule cannot match against a query string in the manner you are trying. You would need to use a RewriteCond before the RewriteRule to achieve that sort of result. Quote Link to comment https://forums.phpfreaks.com/topic/206066-another-redirect-issue-xa-to-xa/#findComment-1078224 Share on other sites More sharing options...
sw0o0sh Posted June 28, 2010 Author Share Posted June 28, 2010 You appear to be using the process backwards. Your links in your site should really be of the format highscores/user/20, this should then be rewritten to the 'ugly' format, not vice versa. Yeah, I'm in the process of changing the format (of the actual links), into the directory style. However, in coding, when somebody hits the submit button in a <form> and it's method is 'get', it creates the ?query=data format string in the URL. I would like to avoid that format all together, I don't really want it half assed at all if it's possible. So, when somebody hits the submit button, I need to know how to get this to redirect into the new/format/ via apache (I could do this via PHP but it just seems ghetto) Incidentally a RewriteRule cannot match against a query string in the manner you are trying. You would need to use a RewriteCond before the RewriteRule to achieve that sort of result. Alright, so this RewriteCond function would achieve the url switch I am looking for? How do I approach this? I just started doing this stuff. And thank you for the replies today Quote Link to comment https://forums.phpfreaks.com/topic/206066-another-redirect-issue-xa-to-xa/#findComment-1078228 Share on other sites More sharing options...
cags Posted June 28, 2010 Share Posted June 28, 2010 RewriteCond %{QUERY_STRING} ^query=([^&]+)$ RewriteRule ^highscores.php /highscores/user/%1 [R=302, NC] Quote Link to comment https://forums.phpfreaks.com/topic/206066-another-redirect-issue-xa-to-xa/#findComment-1078235 Share on other sites More sharing options...
sw0o0sh Posted June 28, 2010 Author Share Posted June 28, 2010 RewriteCond %{QUERY_STRING} ^query=([^&]+)$ RewriteRule ^highscores.php /highscores/user/%1 [R=302, NC] Okay, after googling around with what you told me (seeing as that didn't seem to work, internal error message), I came to a site with a similar problem as mine, probably the same thing give or take http://www.webmasterworld.com/apache/3495477.htm So, I tried this code: RewriteCond %{QUERY_STRING} &?user=([^&]+) [NC] RewriteRule ^highscores\.php$ /highscores/user/%1? [NC,L] But now it's saying the user can not be found, whereas without the script (and the other re-writes), if I went to highscores/user/xxx , it will display their information. Quote Link to comment https://forums.phpfreaks.com/topic/206066-another-redirect-issue-xa-to-xa/#findComment-1078258 Share on other sites More sharing options...
cags Posted June 28, 2010 Share Posted June 28, 2010 What is the exactly query string in the URL that you are using? Quote Link to comment https://forums.phpfreaks.com/topic/206066-another-redirect-issue-xa-to-xa/#findComment-1078269 Share on other sites More sharing options...
sw0o0sh Posted June 28, 2010 Author Share Posted June 28, 2010 Trying to get www.website.com/highscores?user=e (which is generated by a search function I wrote) Converted to www.website.com/highscores/user/e Though I seem to keep getting internal issues w. the snippets I try edit- it seems as though it's not actually switching the url (with this 404 not found error on the other snippet) , it's staying the same ?user=e version, and returning an error saying The requested URL /highscores/user/e was not found on this server. Quote Link to comment https://forums.phpfreaks.com/topic/206066-another-redirect-issue-xa-to-xa/#findComment-1078275 Share on other sites More sharing options...
cags Posted June 28, 2010 Share Posted June 28, 2010 RewriteCond %{QUERY_STRING} ^user=(.*)$ RewriteRule ^highscores$ /user/%1/? [R=302,L] Works fine for me. Quote Link to comment https://forums.phpfreaks.com/topic/206066-another-redirect-issue-xa-to-xa/#findComment-1078284 Share on other sites More sharing options...
sw0o0sh Posted June 28, 2010 Author Share Posted June 28, 2010 Yes that did work, thanks Quote Link to comment https://forums.phpfreaks.com/topic/206066-another-redirect-issue-xa-to-xa/#findComment-1078475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.