Help with some rewrites

Discuss practical ways rearrange URLs using mod_rewrite.

Help with some rewrites

Postby notbean » Thu Apr 16, 2009 11:12 pm

I hope someone can give me a hand with these rewrites. I've got them working on 5 different servers but unfortunately the really important one spits the dummy on the first rule. I have 24 hours before I'm supposed to be going on holidays and regexp right now is *hurting*. Can anyone tell me where I've made the mistake?

RewriteRule ^([a-zA-Z0-9-&_]+)(/)?(.html)?(\?[a-zA-Z0-9-&_]+)?$ index.php?view=$1&$2
RewriteRule ^([a-zA-Z0-9-&_]+)/([a-zA-Z0-9-&_]+)(/)?(.html)?(\?[a-zA-Z0-9-&_]+)?$ index.php?view=$2&p2=$1&$3
RewriteRule ^([a-zA-Z0-9-&_]+)/([a-zA-Z0-9-&_]+)/([a-zA-Z0-9-&_]+)(.html)?(\?[a-zA-Z0-9-&_]+)?$ index.php?view=$3&p2=$2&p3=$1&$4
RewriteRule ^([a-zA-Z0-9-&_]+)/([a-zA-Z0-9-&_]+)/([a-zA-Z0-9-&_]+)/([a-zA-Z0-9-&_]+)(.html)?(\?[a-zA-Z0-9-&_]+)?$ index.php?view=$4&p2=$3&p3=$2&p4=$1&$5
notbean
 
Posts: 3
Joined: Thu Apr 16, 2009 11:07 pm

Postby richardk » Fri Apr 17, 2009 8:30 am

What is it supposed to match?
Where are you putting it?
Does any mod_rewrite work? Try this test.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^([a-z0-9-&_]+)(/|\.html)?$                                            /index.php?view=$1                   [NC,QSA,L]
RewriteRule ^([a-z0-9-&_]+)/([a-z0-9-&_]+)(/|\.html)?$                             /index.php?view=$2&p2=$1             [NC,QSA,L]
RewriteRule ^([a-z0-9-&_]+)/([a-z0-9-&_]+)/([a-z0-9-&_]+)(\.html)?$                /index.php?view=$3&p2=$2&p3=$1       [NC,QSA,L]
RewriteRule ^([a-z0-9-&_]+)/([a-z0-9-&_]+)/([a-z0-9-&_]+)/([a-z0-9-&_]+)(\.html)?$ /index.php?view=$4&p2=$3&p3=$2&p4=$1 [NC,QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby notbean » Fri Apr 17, 2009 1:09 pm

I didn't write this, so I'm not 100% sure *exactly* what it needs to match, I just know it works. The comment says:
# Rewrites from http://www.example.com/pages/my-page-name.html http://www.example.com/index.php?view=my-page-name

Yes, the simple rewrites work.

The error is: RewriteRule: cannot compile regular expression '^([a-z0-9-&_]+)(/|\\.html)?$'\n

I'm putting it in a .htaccess in the root of my site. Putting the test rewrites there works perfectly.

I tried it using your suggestion and it failed (with the above error). Thanks for the suggestion though.
notbean
 
Posts: 3
Joined: Thu Apr 16, 2009 11:07 pm

Postby richardk » Fri Apr 17, 2009 4:06 pm

Try replacing all
Code: Select all
[a-z0-9-&_]

with
Code: Select all
[-a-z0-9&_]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby notbean » Fri Apr 17, 2009 4:17 pm

Thank you so much. That works.
notbean
 
Posts: 3
Joined: Thu Apr 16, 2009 11:07 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 20 guests

cron