Welcome to WebmasterWorld Guest from 54.146.221.231

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod rewrite prob

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

New User

10+ Year Member

joined:Feb 9, 2002
posts:8
votes: 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
www.domain.com/widgets/page.htm

to be served by
www.domain.com/script.php?pg=page&cat=widgets

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)

Thanks!

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


Try

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.

Andreas

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

New User

10+ Year Member

joined:Feb 9, 2002
posts:8
votes: 0


Thanks Andreas!

It worked!

Can you please help with with another problem:

I got a little braver & tried to rewrite
www.domain.com/widgets/page.htm?id=xyz

to be served by
www.domain.com/script.php?pg=page&cat=widgets&id=xyz

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?

Thanks!

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

New User

10+ Year Member

joined:Feb 9, 2002
posts:8
votes: 0


Anyone got any ideas - sure would appreciate some help - thanks!
2:53 pm on Oct 22, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 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.

Andreas

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

New User

10+ Year Member

joined:Feb 9, 2002
posts:8
votes: 0


Andreas

Thanks for your help!

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members