php - 子文件夹的 htaccess 重写规则(漂亮的 url)

标签 php apache .htaccess mod-rewrite

我试图弄清楚如何在子文件夹“admin”中工作,就像在根目录中工作一样,问题是我不知道该怎么做。

目前我有:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ?arg=$1 [L,QSA]

# /
RewriteCond %{REQUEST_URI} !\.[[:alnum:]]+$
RewriteRule ^(.+[^/])$ /$1/ [R=301]

现在它的工作原理是: http://example.com/page翻译成http://example.com/?arg=page

另外我想做的是: http://example.com/admin/page翻译成http://example.com/admin/?arg=page

我完全不知道如何做到这一点,有人可以帮我吗?

谢谢

最佳答案

您可以将这些规则与适当的 RewriteBase 一起使用:

RewriteEngine On
RewriteBase /admin/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ?arg=$1 [L,QSA]

关于php - 子文件夹的 htaccess 重写规则(漂亮的 url),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35757707/

相关文章:

PHP:处理内存和代码低内存使用

php - 用于在 mPDF 中定位嵌套 div 的 CSS 替代方案

php - 使用 htaccess 文件动态 url 重写

apache - mod_rewrite 不重写

regex - HTACCESS重写: Ignore another rewrite rule

php - 如何将操作固定到按钮

php - XPath 2.0 和/或 XSLT 2.0 会在 PHP 中实现吗?

apache - 是什么导致 apache 崩溃并出现错误 "Inconsistency detected by ld.so"?

php - 无法使用 PHP 5.6.14 连接到 oracle 数据库 - OCI 连接问题

php - 我应该在 Windows Server 2008 Enterprise 上安装 xampp 吗