目录中的友好 URL

Friendly URL within a directory

我在域和目录中安装了 Wordpress,我在 PHP+MySQL 中开发了一个完全独立于 wordpress 的站点。它单独工作。本站为后台,所以安装在/backoffice/目录下

后台的一个目录我有另一个目录我希望它与友好的 URL 一起工作。

在我的 .htaccess 中,我有以下规则:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^backoffice/edit_user/([^/\.]+)/?$ /backoffice/edit_user/index.php?o= [L,NC,QSA]


RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !=/server-status
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^login/?$ wp-login.php [QSA,L]
RewriteRule ^postpass/?$ wp-login.php?action=postpass [QSA,L]
RewriteRule ^logout/?$ wp-login.php?action=logout [QSA,L]
RewriteRule ^lostpassword/?$ wp-login.php?action=lostpassword [QSA,L]
RewriteRule ^retrievepassword/?$ wp-login.php?action=retrievepassword [QSA,L]
RewriteRule ^resetpass/?$ wp-login.php?action=resetpass [QSA,L]
RewriteRule ^rp/?$ wp-login.php?action=rp [QSA,L]
RewriteRule ^register/?$ wp-login.php?action=register [QSA,L]

当调用像这样的 url 时:mydomain。com/backoffice/edit_user/joseantonio 出现 404 页面。

怎么了?

提前致谢。

正如在 this answer 中一样 - 您可以调试 Apache 重写。在您的虚拟主机 服务器配置中开启 RewriteLog

RewriteEngine On
RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 3

然后你会看到什么规则使它重定向 404。

最后,我找到了解决方案:

这里是结合wordpress使用的代码:

     <IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^index\.php$ - [L]

**RewriteRule ^backoffice/edit_user/([^/\.]+)/?$ /backoffice/edit_user/index.php?o= [L,NC,QSA]**

    RewriteCond %{REQUEST_URI} !=/server-status
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteRule ^login/?$ wp-login.php [QSA,L]
    RewriteRule ^postpass/?$ wp-login.php?action=postpass [QSA,L]
    RewriteRule ^logout/?$ wp-login.php?action=logout [QSA,L]
    RewriteRule ^lostpassword/?$ wp-login.php?action=lostpassword [QSA,L]
    RewriteRule ^retrievepassword/?$ wp-login.php?action=retrievepassword [QSA,L]
    RewriteRule ^resetpass/?$ wp-login.php?action=resetpass [QSA,L]
    RewriteRule ^rp/?$ wp-login.php?action=rp [QSA,L]
    RewriteRule ^register/?$ wp-login.php?action=register [QSA,L]

如您所见,我在 index.php 规则之后更改了规则的位置,工作正常,在任何其他位置,它都不起作用。

您可以尝试在 /backoffice/ 文件夹中使用自己的 .htaccess

RewriteBase /backoffice/
# all the backofice rules