homepage Welcome to WebmasterWorld Guest from
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

mod rewrite prob

 7:48 pm on Oct 21, 2002 (gmt 0)
I have been pounding my head against the wall for several days & I still can't figure out what I'm doing wrong. Any help would sure be appreciated!

We would like

to be served by

We put this in our htaccess file:
RewriteEngine on
RewriteRule ^/widgets/(.*)\.htm$ /solar.php?pg=$1&page=widgets

We get a 404

What am I doing wrong?

Also, when I get this working, I want to do the same thing for bluewidgets, redwidgets etc.
Do I need separate RewriteRules for each or is there a way to make it a variable (instead of just "widgets"), but only with certain values (bluewidgets, etc)




 9:53 pm on Oct 21, 2002 (gmt 0)


RewriteRule ^widgets/(.*)\.htm$ /solar.php?pg=$1&page=widgets

without the leading slash which is stripped off when the RewriteRule is used in directory context.

RewriteRule ^(redŽblueŽgreen)widgets/(.*)\.htm$ /solar.php?pg=$2&page=$1widgets

should work for all kinds of widgets.



 11:22 pm on Oct 21, 2002 (gmt 0)

Thanks Andreas!

It worked!

Can you please help with with another problem:

I got a little braver & tried to rewrite

to be served by

I used:
RewriteRule ^widgets/(.*)\.htm?id=(.*)$ /solar.php?pg=$1&cat=widgets&id=$2

It didn't work. id=xyz was not in the final query string.

Can this be done with mod rewrite?



 2:46 pm on Oct 22, 2002 (gmt 0)

Anyone got any ideas - sure would appreciate some help - thanks!


 2:53 pm on Oct 22, 2002 (gmt 0)

You cannot access the query string in a RewriteRule. You would need to use RewriteCond [httpd.apache.org] %{QUERY_STRING} for that. RewriteCond defines a condition. The following RewriteRule is only used if this condition is met and the rewrite rule itself matches.

Quite frequently you use RewriteCond not for the condition it allows you to specify but for gaining access to and matching certain parts of a whole lot of server variables.

RewriteCond %{QUERY_STRING} id=([^&]+) 
RewriteRule ^widgets/(.*)\.htm$ /solar.php?pg=$1&cat=widgets&id=%1

RewriteCond takes the QUERY_STRING and tries to match 'id=' followed by one or more characters that are not &. Those characters are stored %1.

You will need an additional RewriteRule (like the one in my previous post) to handle cases where there is no 'id=' in the query string since you made that a condition by specifying the RewriteCond.



 3:04 pm on Oct 22, 2002 (gmt 0)


Thanks for your help!

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