ReWrite Rule question

I just ran into a situation where if I re-use a parameter in a rewrite rule statement it doesn’t work. But if I change the name of the parameter to a new one it works fine. For example, this one works:

RewriteRule ^Working_Quote/([a-zA-Z0-9\-\_]+)$ /grids/index.php?gridurl=$1 [L]
RewriteRule ^Process_Grid/([0-9]+)/([a-zA-Z0-9\-\_]+)?$ /grids/index.php?processgrid=$1&urlname=$2 [L]

But this one does not

RewriteRule ^Working_Quote/([a-zA-Z0-9\-\_]+)$ /grids/index.php?gridurl=$1 [L]
RewriteRule ^Process_Grid/([0-9]+)/([a-zA-Z0-9\-\_]+)?$ /grids/index.php?processgrid=$1&gridurl=$2 [L]

Am I missing something? If I re-use “gridurl” it doesn’t work. Is there a rule against that?

Nope, there isn’t.

Unfortunately that’s about all I can tell you for right now. “It doesn’t work” doesn’t tell us enough about what’s happening or not happening. You should show the htaccess file you’re using, the URL you’re trying to request, and maybe even some of the relevant PHP code. Then describe what you expect to happen and what you actually observe happening.

The htaccess file is below. Regarding what happens it looks like the page is refreshing but I put stops in my primary index file and the /grids index file and it doesn’t see either one of them. Which I suppose says to me that it is just going into htaccess and doing nothing. I don’t get a 404 error and like I said it doesn’t hit either of the indexes.

The url call is

Again, I can run it with the code I showed above using “urlname” and then change urlname (and that’s the only change I make anywhere) to “gridurl” and it won’t process. The action is a form submit that creates that url.

AddHandler php5-script .php

Options +FollowSymLinks -Indexes -MultiViews

ErrorDocument 404 /errors/404page.html

RewriteEngine On

#RewriteCond %{SERVER_PORT} ^443$
#RewriteCond %{HTTP_HOST} ^www\.abc\.com$ [NC]
#RewriteRule .?{REQUEST_URI} [L,R=301]

RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} ^www\.abc\.com$ [NC]
RewriteRule .?{REQUEST_URI} [L,R=301]

RewriteRule ^Home/?$ /index.php?home [L]

RewriteRule ^Create_Quote/?$ /grids/index.php?createquote [L]
RewriteRule ^Submit_PO/?$ /grids/index.php?submitpo [L]
RewriteRule ^Working_Quote/([a-zA-Z0-9\-\_]+)$ /grids/index.php?gridurl=$1 [L]
RewriteRule ^Grid_Page/([0-9]+)$ /grids/index.php?gridmasterid=$1 [L]
RewriteRule ^Saved_Quote/([0-9]+)$ /grids/index.php?savedquote=$1 [L]
RewriteRule ^Process_Grid/([0-9]+)/([a-zA-Z0-9\-\_]+)?$ /grids/index.php?processgrid=$1&urlname=$2 [L]
RewriteRule ^Product_List/?$ /grids/index.php?productlist [L]

RewriteRule ^My_Account/?$ /users/index.php?%1 [L,QSA]
RewriteRule ^Login/?$ /users/index.php?loginpage [L,QSA]

One more thing. I tried it also with gridmasterid which was previously used and it did not run correctly which is what made me think it might be a rule of some sort. Any unused parameter seems to work fine.


I see nothing technically wrong with your code(s) (I have a minor problem with your long character range definitions - the placement of the - and the unnecessary use of the 's) so I recommend that, before further alterations, you add R=301 to your Last flags so you can VIEW the redirections (remove after you’re satisfied that they work).

About a “rule against that,” each RewriteRule is creating its own set of variables (the $1 … $9) and each stands alone. That said, each can use whatever redirection it needs.



Thanks for the input. First question before I begin to dig into this further because I would like to ultimately find out why this is happening, how would you format the character range definitions to include numbers, letters, - and /?

Currently is /([a-zA-Z0-9\-\_]+)$

Here are the variations and what happens (but read the end of the note first!!)

  1. Start with the one that works fine
    RewriteRule ^Process_Grid/([0-9]+)/([a-zA-Z0-9-_]+)?$ /grids/index.php?processgrid=$1&urlname=$2 [L] – works great, no problems

  2. Change the urlname to gridurl
    RewriteRule ^Process_Grid/([0-9]+)/([a-zA-Z0-9-_]+)?$ /grids/index.php?processgrid=$1&gridurl=$2 [L] – the page doesn’t change but the url goes to /Process_Grid/1/Str_Tops which is what was sent in from the form. What I am trying to catch is processgrid so in the index I put a break in the if statement looking for processgrid and it never goes there.

  3. Add the R=301
    RewriteRule ^Process_Grid/([0-9]+)/([a-zA-Z0-9-_]+)?$ /grids77040/index.php?processgrid=$1&gridurl=$2 [L,R=301] – The page never processes (it has the same behavior as #2) thru the index file but the url does change to “/grids/index.php?processgrid=1&gridurl=Str_Tops”

  4. Change it back to urlname
    RewriteRule ^Process_Grid/([0-9]+)/([a-zA-Z0-9-_]+)?$ /grids/index.php?processgrid=$1&urlname=$2 [L,R=301] – page works as intended and goes to the stop in the grids index inside the $_GET[‘processgrid’]. The url reads “/grids/index.php?processgrid=1&urlname=Str_Tops”

And with that I just realized what is happening. In the index file there is a $_GET[‘gridurl’] before the $_GET[‘processid’] so it is going to that and that is the one that builds the page that I am on. So it is coincidental that it stays on the same page and the whole thing is working as programmed! A real duh moment. :smile:

Although I could swear I put the break at the top of the index page at one point and it never hit but oh well.

Thanks for the help and sorry to put you through that. But it really helps knowing what it is not sometimes so without your guidance I would not have found it. Probably just would have left it as urlname.


numbers: [0-9]+
letters: [a-zA-Z]+
hyphens: This is a metacharacter within a character range definition. The Apache documentation says, to be considered a hyphen character, it must be placed first. In the wild, though, it can also be placed last as this also avoids confusion with the metacharacter. [-…]+ or […-]+
slashes: [/]+ this does not need to be escaped BUT it radically changes the browser’s perceived level in your file hierarchy so it’s advisable NOT to include it within a character range definition (relative links would be relative to the level of the {REQUEST_URI}.

On to your other post …




Ha! Problem resolved? Gudonya. It takes me another set of eyes (or a rest period away from the problem) to see where the problem is.



Yes. Can’t say how many times I have not been able to find something late at night and then in the morning you find it right away. I can get pretty myopic sometimes. :flushed:

Again, thanks for the assistance. I do appreciate it.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.