Forum Moderators: phranque

Message Too Old, No Replies

create a dynamic url

create a dynamic url

         

xbl01234

9:39 am on Nov 19, 2007 (gmt 0)

10+ Year Member



Hi;
i am trying to create a dynamic url, the format is like following:
www.mysite.com/book/category?page=1 or www.mysite.com/movie/category?page=1 etc.

and i wrote a mod_rewrite rule in .htaccess file, which is

RewriteEngine On
RewriteRule ^([a-z]+)/Category.php?page=1$ /Category.php?cateName=$1 [L]

and i also create a file called Category.php sit in public_html folder.

and then in the index.php file, i have a link like as following

<a href="country/Category.php?page=1"> click me </a>

but the problem is that it doesn't create a dynamic url for me when i click the above
link, it tell me it could not find the file.

Could anyone help me, please

jdMorgan

12:33 pm on Nov 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule cannot 'see' query strings. Use a RewriteCond:

RewriteCond %{QUERY_STRING} ^page=([^&]+)
RewriteRule ^([a-z]+)/Category\.php$ /Category.php?cateName=%1 [L]

Jim

xbl01234

8:56 am on Nov 20, 2007 (gmt 0)

10+ Year Member



Thanks for your help.

xbl01234

9:08 am on Nov 20, 2007 (gmt 0)

10+ Year Member



>RewriteCond %{QUERY_STRING} ^page=([^&]+)
your Rewritecod works very well.

But i want to ask you a question about the regular expression of the
([^&]+), what does it means?
if i write it, i will write like ([0-9]+]&([0-9]+)

but your one more simple.

Would you express what does the ([^&]+) means? Thanks

phranque

1:36 pm on Nov 20, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



([^&]+) matches one or more characters that are not an ampersand and marks this as a subexpression that can be recalled later with a $1, %1 or \1 backreference, depending on context.

jdMorgan

3:39 pm on Nov 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have more query string parameters before or after, or before and after the "page=", then the code must be re-designed to handle them properly. Otherwise, even if the RewriteCond matches, they will be lost by the code above.

Jim

xbl01234

8:45 am on Nov 21, 2007 (gmt 0)

10+ Year Member



Thanks a lot