开发者

htaccess simple rewrite rule being ignored

开发者 https://www.devze.com 2023-04-13 05:35 出处:网络
I have two rewrite rules, this is what I\'m trying to achieve user link -> internal link site.com/dir1/dir2/ab-mypage.php?page=3 -> site.com/dir1/dir2/script.php?code=ab&page=3

I have two rewrite rules, this is what I'm trying to achieve

user link -> internal link

site.com/dir1/dir2/ab-mypage.php?page=3 -> site.com/dir1/dir2/script.php?code=ab&page=3

site.com/dir1/dir2/cd-mypage.php -> site.com/dir1/dir2/script.php?code=cd

As you can see, the second one is just the same as the first but with pagination support.

Here is the htaccess code:

RewriteRule ^dir1/dir2/(.*)-mypage.php?page=(.*)$ dir1/dir2/script.php?code=$1&page=$2
RewriteRule ^dir1/dir2/(.*)-mypage.php$ dir1/dir2/script.php?code=$1

The pagination rule is being ignored completely, no errors. In my script.php when I print out the querystring, the only variable that is present is code. I need the page number to be present as well for the second rule.

Edit: Incase anyone else has this problem, this might help: the question mark (?) is the problem, 开发者_Python百科if I use a different character it works and I get both variables. This may be a solution if you don't care about the question mark. To keep the question mark, use the accepted answer to resolve.


Instead of making 2 rules, use [QSA] (which stands for Query String Append) - it will append the original query string to the modified one:

RewriteRule ^dir1/dir2/(.*)-mypage.php$ dir1/dir2/script.php?code=$1 [QSA]


Query string is being ignored. You don't need the first rule, just use the QSA flag:

RewriteRule ^dir1/dir2/(.*)-mypage.php$ dir1/dir2/script.php?code=$1 [QSA]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号