URL重写不断返回404错误

时间:2014-06-27 06:41:02

标签: php apache .htaccess mod-rewrite url-rewriting

我已经为URL重写创建了一个.htaccess文件,我使用http://htaccess.madewithlove.be/对其进行了测试,并且它说URL重写是正确的,但是在测试页面时一直给我404错误。

这是.htaccess:

RewriteEngine On
RewriteBase /

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

我需要的URL重写如下:

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

有谁能告诉我我搞砸了什么? 谢谢!

1 个答案:

答案 0 :(得分:1)

首先,确保存在名为/article/index.php的文件,然后尝试一下:

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