Web Worm
Web Worm

Reputation: 2066

how can i solve this htaccess problem

i have following dynamic url...

http://www.mydomain.com/v/dynamicvaluehere

and i have following in my htaccess

RewriteRule ^v/(.*)$ script.php?name=$1 [NC,L]

and it is working fine now i want to create further i.e

http://www.mydomain.com/v/dynamicvaluehere/Page-dyanamicnumberhere.html

and i have following in my htaccess

RewriteRule ^v/(.*)/Page-(.*)\.html$ script.php?name=$1&number=$2 [NC,L]

but it is not working please help... also do note that the dynamicvalue mentnioned secondly is samy as mentioned above but only dynamicnumber is further included...

Upvotes: 0

Views: 59

Answers (2)

Jason McCreary
Jason McCreary

Reputation: 73031

Your second rule is never being reached because of the greedy nature of the first. You can either put it above the first rule or make your first rule more specific.

Try the following:

RewriteRule ^v/(.+)/Page-(.+)\.html$ script.php?name=$1&number=$2 [NC,L]
RewriteRule ^v/(.*)$ script.php?name=$1 [NC,L]

Upvotes: 0

jacrough
jacrough

Reputation: 168

I think the problem might be your use of wildcards. If your .htaccess looks like this:

RewriteRule ^v/(.*)$ script.php?name=$1 [NC,L]
RewriteRule ^v/(.*)/Page-(.*)\.html$ script.php?name=$1&number=$2 [NC,L]

then no pattern will ever reach the second argument because (.*)/Page-(.*)\.html will actually fall under (.*) first.

You could either refine your wildcards to something like this:

RewriteRule ^v/([A-Za-z0-9].*)$ script.php?name=$1 [NC,L]
RewriteRule ^v/([A-Za-z0-9].*)/Page-([0-9].*)\.html$ script.php?name=$1&number=$2 [NC,L]

or maybe even try switching the order of your statements to:

RewriteRule ^v/(.*)/Page-(.*)\.html$ script.php?name=$1&number=$2 [NC,L]
RewriteRule ^v/(.*)$ script.php?name=$1 [NC,L]

Upvotes: 1

Related Questions