Hello, I have a problem with a rewrite rule I'd like to use. I want to make my url from domain/index.php?page=view&view=type&id=2&offset=12 to domain/view/type/2?12. Is this possible ? I have tried a few patterns but non ot them worked and now i'm stuck with this RewriteRule ^([a-z]+)/([a-z]+)/([0-9]+)\?([0-9]+)$ index.php?page=$1&$1=$2&id=$3&offset=$4 [L] But it doesn't work. If anyone have used a similar rule please help me out
I think I found the problem. Now I need a solution. I have a previous rule that looks like this: RewriteRule ^([a-z]+)/([a-z]+)/([0-9]+)$ index.php?page=$1&$1=$2&id=$3 [L] And the url is like domain domain/view/type/3. But if I remove the rule and leave only the next one RewriteRule ^([a-z]+)/([a-z]+)/([0-9]+)?([0-9]+)$ index.php?page=$1&$1=$2&id=$3&offset=$4 [L] it oppens the page but looks like my variables are empty in case page, view, id, offset because it doesn't display any content on the page . I also tried adding a \ before the ? but in that case it doesn't even display the page. Any ideas ?
As far as I know, in your rewrite rule, you can't fetch what's after an ? (the query string). So the rewrite rule can't apply since you can't have an url with "?" in it. I think you have to use a RewriteCond RewriteCond %{QUERY_STRING} FORMAT with (variables) and get variables in it, which should be usuable after in your rewrite url as %1, %2, etc. I think, I'm not an expert. It would probably be alot of trouble for me to make that work. But I'm almost sure you have to do it this way.
Good advice for the query string. Thanks to it it I've wrote a rule that looks like: RewriteCond %{QUERY_STRING} offset=([0-9]) RewriteRule ^([a-z]+)/([a-z]+)/([0-9]+)$ index.php?page=$1&$1=$2&id=$3&offset=%1 [L] And it rewrites my url like: domain/estate/view/type/3?offset=2 Now the only problem is that I can't access the url without ?offset. If I write only: domain/estate/view/type/3 the result is "tha page cannot be display". So I need to make the offset optional. How do I do that ?
so after a few hours of testing different patterns and stuff I found a solution RewriteCond %{QUERY_STRING} offset=([0-9]) RewriteRule ^([a-z]+)/([a-z]+)/([0-9]+)$ index.php?page=$1&$1=$2&id=$3&offset=%1 [L] RewriteRule ^([a-z]+)/([a-z]+)/([0-9]+)$ index.php?page=$1&$1=$2&id=$3 [L] Not sure if that's the right one but it works for now so I'll use until something goes wrong... hope it won't happen. thanks for the help