首页 文章

集成Wordpress和自定义URL重写

提问于
浏览
0

我正在使用Wordpress 3.4.1打开永久链接 . 在我的.htaccess中,我有以下代码:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

我还想设置自定义重写(不是重定向),以便在用户访问此URL时:

http://example.com/about/video-center/youtubeID/title-slug/

它在内部被重写为:

http://example.com/about/video-center/

现在,第一个URL 404s .


我尝试在 RewriteBase / 行之后将此规则添加到我的.htaccess:

RewriteRule ^about/video-center/(.+)$ /about/video-center/ [NC,L]

什么都不做(我仍然得到404) . 如果我在标志中添加 R ,那么它会重定向和/ about / video-center / loads就好了,这让我相信规则是匹配和重写的 .


我的理论是重写工作正常......但是当WP的重写规则生效时,我所覆盖的任何自定义重写规则都被覆盖 - 即使它在内部重写,WP仍然试图处理地址栏中的URL .

我不知道如何绕过这个并使我的自定义重写与Wordpress一起工作 .

现在,我意识到可能无法单独从.htaccess获得我想要的结果,并且可能需要一个插件或我的Theme的functions.php中的一些自定义代码来解决这个问题 . 我愿意接受任何解决方案 .

2 回答

  • 0

    This看起来很有希望 . (从WP 's docs) Check out the first example there - You can probably skip adding a query var, since the rewrite you'重新寻找似乎更简单 .

    但是,ID / url-slug会发生什么?不再需要这些信息?

  • 0

    花了太多时间试图为此找到解决方案,我只想使用哈希:

    http://example.com/about/video-center/#youtubeID/title-slug/

相关问题