简体   繁体   English

结合CakePHP和Wordpress .htaccess规则

[英]Combining CakePHP and Wordpress .htaccess rules

I've got a problem that seems relatively straightforward but I don't know exactly how to get mod_rewrite and .htaccess to behave the way I want them to. 我有一个看似相对简单的问题,但我不完全知道如何使mod_rewrite和.htaccess发挥我希望它们的作用。 First off, I have a Wordpress install in the /webroot directory of my CakePHP app (in the subfolder "blog"). 首先,我在CakePHP应用程序的/ webroot目录中(在子文件夹“ blog”中)安装了一个Wordpress。 That works fine, as in, I can access: 效果很好,因为我可以访问:

site.com/blog/ site.com/blog/
site.com/blog/about/ site.com/blog/about/
etc... 等等...

Since I would like wordpress to power a few static pages on my site, I would like some of these Wordpress pages to have "root" level URLs, eg 由于我希望wordpress为我网站上的一些静态页面提供动力,因此我希望其中的某些Wordpress页面具有“根”级URL,例如
site.com/about (which would actually be the WP page /blog/about) site.com/about(实际上是WP页面/ blog / about)

If I have permalinks turned off on my WP site (ie the .htaccess file in /webroot/blog is empty), then this works pretty well. 如果我在WP网站上关闭了永久链接(即/ webroot / blog中的.htaccess文件为空),则此方法效果很好。 In my /app .htaccess file, I use: 在我的/ app .htaccess文件中,我使用:

RewriteRule ^about /blog/index.php?page_id=2 [NC,L]

Then I can go to site.com/about and it works. 然后,我可以转到site.com/about ,它可以正常工作。 But, I would prefer to use "pretty permalinks" in my WP site, so that once you get to the WP site and you're clicking around, the links don't look like "index.php?page_id=...". 但是,我宁愿在我的WP网站中使用“漂亮的永久链接”,以便一旦您到达WP网站并单击时,链接看起来就不会像“ index.php?page_id = ...” 。 The problem is that if I turn permalinks on, when I go to site.com/about it will redirect (ie change my address bar) to site.com/blog/about which I don't really want. 问题是,如果我打开永久链接,则当我访问site.com/about时 ,它将重定向(即更改地址栏)到我不想要的site.com/blog/about If I instead use: 如果我改用:

RewriteRule ^about /blog/about [NC,L]

It does take me to my WP site, but with a 404 page not found. 它的确将我带到了我的WP网站,但是找不到404页面。 I'm guessing this all has something to do with the fact that my rewrite rule is directing to WP, which then applies its own rewrite rules. 我猜这一切与我的重写规则将直接定向到WP有关,然后WP应用了自己的重写规则。

So, the bottom line is that I would essentially like to "hardcode" particular URLs like site.com/about and have them be hooked up to WP pages, while preserving the hardcoded URL in the address bar. 因此,最重要的是,我本质上希望对诸如URL.com/about之类的特定URL进行“硬编码”,并将它们连接到WP页面,同时在地址栏中保留硬编码的URL。
Any ideas? 有任何想法吗? Thanks! 谢谢!

尝试使用: RewriteRule ^about /blog/about [NC]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM