Jump to content

RewriteRule doesn't work!


Adam

Recommended Posts

This could be entirely wrong, but if I remember correctly, the query string is not included in the URL during the RewriteRule statement (kind of strange, but makes sense if you think about the HTTP specification).

 

 

You could do something like:

 

RewriteCond %{QUERY_STRING} ^forgot\?([0-9]+)$

RewriteRule ^$ /request.php?forgot_code=%1

Thanks for taking a look. Unfortunately though when I try to test that I'm just getting a 404 error, seems like it's trying to find it as an actual file. In case anyone asks as well here's the full file:

 

RewriteEngine On
RewriteCond %{QUERY_STRING} ^forgot\?([0-9]+)$
RewriteRule ^$ /request.php?forgot_code=%1

 

Thanks again!

Oh wow....  I'm an idiot...  Not sure why I went with ^$....

 

^$ matches an empty string lol.

 

 

Try:

 

RewriteEngine On

RewriteCond %{QUERY_STRING} ^forgot\?([0-9]+)$

RewriteRule ^ /request.php?forgot_code=%1

 

Or, if you want to be more proper, you could just do something like:

 

RewriteEngine On

RewriteCond %{QUERY_STRING} ^forgot\?([0-9]+)$

RewriteRule .* /request.php?forgot_code=%1

 

Or perhaps even:

 

RewriteEngine On

RewriteCond %{QUERY_STRING} ^forgot\?([0-9]+)$

RewriteRule . /request.php?forgot_code=%1

Ahhh....  QUERY_STRING as the name implies, is only the query string....  (For page?blah, only 'blah' would be included.)

 

 

Meaning you either need to change that to be REQUEST_URI or change the rewrite to something like this:

 

 

RewriteEngine On

RewriteCond %{QUERY_STRING} ^([0-9]+)$

RewriteRule ^forgot$ /request.php?forgot_code=%1

 

 

I have tested that one, and it works for me.

 

 

You could just change QUERY_STRING to REQUEST_URI if you wanted, but either way should work.  (The REQUEST_URI way might be more efficient if you have any other pages that will have the format page?numbers, and only numbers will be after the ?.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.