【发布时间】:2017-10-04 08:40:10
【问题描述】:
我只是第一次涉足 .htaccess URL 重写的世界,但遇到了第一道障碍。但是我确定我遗漏了一些明显的东西......:)
我的 htaccess 目前看起来像这样,这是一个从 /wordpress 运行的 Wordpress 安装,但被重新编写以显示在域的顶层:
php_value short_open_tag 1
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) wordpress/$2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ wordpress/$2 [L]
RewriteRule . index.php [L]
</IfModule>
我想添加一个重写规则以允许任何人访问: /publication-details.php?id=xxx(其中 xxx 是一个数字 至 /publications/pub-xxx/
我认为这样的事情会起作用:
RewriteRule ^publication-details.php?id=([0-9]+) /publications/pub-$1 [NC]
但我已尝试将其作为一项规则,但它不起作用 - 无论我在现有规则中的哪个位置订购它。尝试访问 /publication-details.php 只会得到 404(Apache 默认)。如果我尝试 /whatever(即 URL 中没有扩展名),我会得到 Wordpress 404。
我错过了什么?!
提前致谢。
【问题讨论】:
标签: wordpress apache .htaccess url-rewriting