Europeuser Europeuser - 27 days ago 16
PHP Question

.htaccess to load index.php file for friendly url

lets say I have this url:
www.mywebsite.com/news/best-ever-phones

The part best-ever-phones is variable and could be anything.
index.php file is checking database for article with url best-ever-phones

The problem is that in ./news/.htaccess file I have this code:

RewriteEngine On
RewriteBase /news/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ index.php?article=$1 [L,QSA]


which is supposed to load index.php file but server returns error 404 Not found when I visit www.mywebsite.com/news/best-ever-phones url

What is wrong, please help

Thanks

Answer

Try this

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule   ^(.+)$   index.php?article=$1   [L]
Comments