Jump to content

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/206066-another-redirect-issue-xa-to-xa/
Share on other sites

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.

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

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.