Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess with multiple variables

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

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

New User

joined:June 18, 2011
posts: 3
votes: 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/main - this passes article=main

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

can someone please help me out?
9:26 am on June 18, 2011 (gmt 0)


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

joined:Aug 10, 2004
votes: 8

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]

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

Senior Member

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

joined:July 3, 2002
votes: 0

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.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members