Welcome to WebmasterWorld Guest from 54.226.246.160

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess with multiple variables

RewriteRule ^news/?(.*)/?(.*)$ index.php?page=news&article=$1&pagenum=$2

     

MikeElmore

8:44 am on Jun 18, 2011 (gmt 0)



ok so I have this site where the following variables are being passed through the url: index.php?page=something
based on what 'something' is will determine other variables to be passed, for example:
if something = news then pass $article and $pagenum
This is my htaccess rule for this:

RewriteRule ^news/?(.*)/?(.*)$ index.php?page=news&article=$1&pagenum=$2 [NC,L]


This works fine for:
url.com/news
url.com/news/main - this passes article=main

however:
url.com/news/main/2 - passes article=main/2 instead of article=main pagenum=2

can someone please help me out?

phranque

9:26 am on Jun 18, 2011 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, MikeElmore!

the .* pattern is "promiscuous, ambiguous and greedy", so the first ".*" in your pattern will match everything after "news/" and the "/?(.*)$" pattern will match "nothing" at the end of the current URL.

check out this thread which should give you some good clues for your solution.
rewriterules for multi-level folders:
http://www.webmasterworld.com/forum92/3771.htm [webmasterworld.com]

[edited by: phranque at 9:46 am (utc) on Jun 18, 2011]

g1smd

9:40 am on Jun 18, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



The /? makes the slash optional. Combined with the .* pattern the parser has NO idea what you actually want.

You'll need separate rules for different folder depths.

The NC flag promotes Duplicate Content within your site. Ensure your script checks that requests are correctly cased and issues a redirect to the correct URL if not.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month