Hello,
I am creating an application with rewirte using .htaccess file.
The rule I have applied is as below
RewriteRule ^(.*)-(.*)\.html$ $1.php?page=$2 [L]
The rule, works like
news-1.html then it will redirect to news.php?page=1
Upto this it works fine.
But when I pass the query string variables like news-1.html?year=2009
then
its not giving me year param and its value in $_REQUEST['year']
Can anybody help me?
Mukesh Variya
Offshore Web Developer India
http://www.mukeshvariya.com
rewrite problem with query string
Moderators: egami, macek, gesf
-
- New php-forum User
- Posts: 92
- Joined: Tue Aug 17, 2010 2:00 am
- Location: Ukraine Kharkov
- Contact:
You need to understand regExps because mod_rewrite based on PREL regexps.
Here you say to script that he need to search all url which starts with any number of symbols after them it is "-" and after it again the set of symbols at the end of script:
So your new url news-1.html?year=2009 is parsed by mod_rewrite like:
because you said to script that html$ html is the end.
You need something like:
Here you say to script that he need to search all url which starts with any number of symbols after them it is "-" and after it again the set of symbols at the end of script:
Code: Select all
RewriteRule ^(.*)-(.*)\.html$ $1.php?page=$2 [L]
Code: Select all
news-1.html?year=2009 -> news.php?page=1
You need something like:
Code: Select all
RewriteRule ^(.*)-(.*)\.html\?(.*)$ $1.php?page=$2&$3 [L]
RewriteRule ^(.*)-(.*)\.html$ $1.php?page=$2 [L]