I have two files in my root directory: news.php
and news-detail.php
. And I want them to be hadled next way:
example.com/news -> /news.php
example.com/news/(\d+) -> /news-detail?id=(\d+)
So I decided to make rewrite with my .htaccess
:
RewriteRule ^news/(\d+)$ /news-detail?id=$1 [L]
But this doesn't works. As I can understand, apache hadles the beggining of url as news.php and don't let the rule work. It look tricky it don't recognize the written regexp. Then I decide to add check if file exists, but it doesn't work either:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
How can I deal with it? The only way I see is to rename news.php
(to news-all.php
, for example) and add one rule to .htaccess
:
RewriteRule ^news$ /news-all [L]
RewriteRule ^news/(\d+)$ /news-detail?id=$1 [L]
Is there any other way?