URL Rewrite keeps returning 404 Error

2019-07-20 07:48发布

问题:

I've created a .htaccess file for the URL rewrite, and I tested it using http://htaccess.madewithlove.be/ and it says the URL rewrite is correct, but when testing the page keeps giving me a 404 error.

Here is the .htaccess:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^article/(.*)$ /article/index.php?id=$1 

The URL rewrite I need is the following:

http://www.mydomain.com/article/test  // To redirect to: 
http://www.mydomain.com/article/index.php?k=test

Can anyone tell me what I am messing up? Thank You!

回答1:

First, make sure a file exists named /article/index.php and then give this a try:

RewriteEngine On
RewriteBase /
# Condition: the requested file is non-existent
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^article/(.*)$ /article/index.php?id=$1 [L,R=301]