Reputation: 863
I'm trying to build an htaccess file that displays an index file on a blank URI, or a numeric slug (pages), such as: example.com or example.com/12 (the later appending ?page=$1)
However when accessing any non-numeric slug, it should go to a different page. For some reason, I can't get it to ever hit the index file (even when blank or numeric). What am I missing?
Here's what I have:
Options All
RewriteEngine On
RewriteRule ^([0-9]*)/?$ index.php?page=$1 [L]
RewriteRule ^([^/]+)/?$ another_page.php?slug=$1 [L]
Shouldn't a blank URI or numeric URI hit the first rule, with the Last flag, and load index.php? Every request I make is hitting another_page.php
Thanks!
Upvotes: 2
Views: 245
Reputation: 863
Ah ha, I figured it out shortly after posting this question.
I did require the RewriteCond lines above the final, but the original files had to exist too. I setup this htaccess file before creating the index.php file (I was looking for a 404).
This is what worked:
Options All
RewriteEngine On
RewriteRule ^([0-9]*)/?$ index.php?page=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ another_page.php?slug=$1 [L]
Thanks guys!
Upvotes: 1