Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod rewrite prob



7:48 pm on Oct 21, 2002 (gmt 0)

10+ Year Member

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)

WebmasterWorld Senior Member 10+ Year Member


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)

10+ Year Member

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)

10+ Year Member

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


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

WebmasterWorld Senior Member 10+ Year Member

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)

10+ Year Member


Thanks for your help!


Featured Threads

Hot Threads This Week

Hot Threads This Month