0

I'm having a problem with my rewrite rules.

RewriteRule blogs/$ /alpha/index.php?m=blog
RewriteRule blogs$ /alpha/blogs/ [R]
RewriteRule blogs/(.*)/$ /alpha/index.php?m=blog&p=name&name=$1
RewriteRule blogs/(.*)$ /alpha/blogs/$1/ [R]
RewriteRule blogs/(.*)/(.*)/$ /alpha/index.php?m=blog&p=post&user=$1&post=$2
RewriteRule blogs/(.*)/(.*)$ /alpha/blogs/$1/$2/ [R]

Some URLs would be: /alpha/blogs/dennis/Test_Blog_Post/
/alpha/blogs/dennis/

Now, with the Rules I posted, when I visit the latter page (the blog homepage) it works fine, the homepage is displayed. Here's the GET data:

Array ( [m] => blog [p] => name [name] => dennis/Test_Blog_Post )

When I visit the first link, a blog post, it shows the blog homepage again, but this time with no information, and a No Posts Found message. Here's the GET data:

Array ( [m] => blog [p] => name [name] => dennis/Test_Blog_Post )

When I change the rewriterules to the following, it gives the same error, only opposite. i.e. the blog post shows, but the homepage doesn't.

RewriteRule blogs/$ /alpha/index.php?m=blog
RewriteRule blogs$ /alpha/blogs/ [R]
RewriteRule blogs/(.*)/(.*)/$ /alpha/index.php?m=blog&p=post&user=$1&post=$2
RewriteRule blogs/(.*)/(.*)$ /alpha/blogs/$1/$2/ [R]
RewriteRule blogs/(.*)/$ /alpha/index.php?m=blog&p=name&name=$1
RewriteRule blogs/(.*)$ /alpha/blogs/$1/ [R]

I really appreciate any help with this.

2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by MattEvans
0

Your usage of '.' is possibly bad:

blogs/(.*)/(.*)/$
blogs/(.*)/$

Both of these will match for 'blogs/folder/folder/'. Because '.*' means anything including 'folder' or 'folder/folder' So, in that case the rule that is checked first will be the one that redirects successfuly.
Try using:

blogs/(.*?)/(.*?)/$
blogs/(.*?)/$

or

blogs/([^/])/([^/])/$
blogs/([^/])/$

and replace all other uses of '.' except where no ambiguity could possibly arrise.

You should also note, that this: blogs/(.*)/(.*)$ should probably match 'blogs/test/' aswell as 'blogs/test/test'; because .* means zero or more anythings.

Put [L] flags on the end of each rule as well, because they all look like they should be terminals..

If you're still having problems, post (exactly) what it is you want do; it seems like your trying to do at least 2 folder/query transformations, add trailing slashes where they're missing, and some of your rules are perhaps redundant/conflicting.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.