从另一个目录重写文件

时间:2015-04-19 11:53:25

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

我正在尝试在另一个目录中重写文件,但它会出错。

  

未找到

     

在此服务器上找不到请求的URL / admin / posts / edit / 1.

     

此外,尝试时遇到404 Not Found错误   使用ErrorDocument来处理请求。

/public_html
    /admin
         /.htaccess
         /posts

我需要从此www.example.com/admin/posts/edit/1

执行此操作www.example.com/admin/posts/edit.php?id=1

我的.htaccess中有这段代码:

RewriteEngine On

RewriteRule ^edit/([0-9a-zA-Z]+) /admin/posts/edit.php?id=$1 [NC,L]

1 个答案:

答案 0 :(得分:0)

创建文件/admin/.htaccess并放置此规则:

Options -MultiViews
RewriteEngine On
RewriteBase /admin/

RewriteRule ^posts/edit/([0-9a-z]+)/?$ posts/edit.php?id=$1 [NC,L,QSA]