Board index   FAQ   Search  
Register  Login
Board index PHP Your Scripts

rewrite problem with query string

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

rewrite problem with query string

Postby Mukseh » Thu Nov 12, 2009 4:07 am

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
User avatar
Mukseh
New php-forum User
New php-forum User
 
Posts: 156
Joined: Wed Mar 22, 2006 2:22 am
Location: Ahmedabad, Gujarat, India

Re: rewrite problem with query string

Postby levis12 » Tue Aug 10, 2010 3:13 am

Rewrite engine is a type of software. It modifies a web URL's appearance. This process adds a degree of separation between the files used to generate a web page and the URL that is presented to the world...


________________________________________________________
Want to get-on Google's first page and loads of traffic to your website? Hire a SEO Specialist from Ocean Groups seo pecialist
levis12
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Aug 10, 2010 2:49 am

Re: rewrite problem with query string

Postby Suhoij » Mon Aug 23, 2010 11:44 pm

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:
Code: Select all
RewriteRule ^(.*)-(.*)\.html$ $1.php?page=$2 [L]


So your new url news-1.html?year=2009 is parsed by mod_rewrite like:
Code: Select all
news-1.html?year=2009 ->  news.php?page=1

because you said to script that html$ html is the end.
You need something like:
Code: Select all
RewriteRule ^(.*)-(.*)\.html\?(.*)$ $1.php?page=$2&$3 [L]
RewriteRule ^(.*)-(.*)\.html$ $1.php?page=$2 [L]
Suhoij
New php-forum User
New php-forum User
 
Posts: 92
Joined: Tue Aug 17, 2010 2:00 am
Location: Ukraine Kharkov


Return to Your Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron