0

I have the following modrewrite rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^blog/([^/]*)/([^/]*)/$ /blog.php?date=$1&title=$2 [L]

Which is pretty straightforward. My question is, how do I get this rewrite to direct to blog.php if no variables are listed?

blog.php is written to both produce the article listing if no variables are present, and also to create the individual listing if one is present.

Edit: blog.php works fine without mod rewrite. If I go to http://host/blog.php it lists all my articles. If I go to http://host/blog/2010-10-05/blog-title/ it shows my single entry. Similarly, if I go to http://host/blog.php?date=2010-10-05&title=blog-title I get a single entry. However, I want http://host/blog/ to list all my entries as well.

I guess the question is: Does this require a second rewrite rule? And if so, how do I get the two to play nice.

2
  • Which is pretty straightforward. My question is, how do I get this rewrite to direct to blog.php if no variables are listed? care to make an example ? not entirelly sure i understood your point... From what i understood it seems more like a programming issue then a rewrite rule issue. It would be a blog.php programming thing to instead of trying to show the article to show something else when there is no available article on the given variables.
    – Prix
    Oct 11, 2010 at 3:21
  • 1
    Or are you saying you just want to redirect blog when people type blog like: RewriteRule ^(blog|blog/)$ /blog.php [L] which would come before your other rule.
    – Prix
    Oct 11, 2010 at 3:25

1 Answer 1

1

From the comments talk, there you go ;)

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(blog|blog/)$ /blog.php [L]
RewriteRule ^blog/([^/]*)/([^/]*)/$ /blog.php?date=$1&title=$2 [L]

The blog alone comes first so if the user have typed blog or blog/ it will go to blog.php and stop there, if that requirement does not meet it will move to the second rule.

(blog|blog/)$

The $ is used to prevent that blog matchs blog.html or anything else.

The | is use as an operator OR so if it is blog OR blog/

[L] means LAST so if the rule is meet no other rule will be take into consideration after it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .