homepage Welcome to WebmasterWorld Guest from 54.205.207.53
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess with multiple variables
RewriteRule ^news/?(.*)/?(.*)$ index.php?page=news&article=$1&pagenum=$2
MikeElmore



 
Msg#: 4327702 posted 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

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



 
Msg#: 4327702 posted 9:26 am on Jun 18, 2011 (gmt 0)

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

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4327702 posted 9:40 am on Jun 18, 2011 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved