简体   繁体   English

使用.htaccess重写到Wordpress子目录?

[英]Using .htaccess to rewrite to Wordpress subdirectory?

As opposed to many questions here in StackOverflow, I'm looking for something a little different. 与StackOverflow中的许多问题相反,我正在寻找一些不同的东西。 I have a Wordpress install in a subfolder of my domain called "blog". 我在域的名为“博客”的子文件夹中安装了Wordpress。 The main part of the website is a Magento website. 该网站的主要部分是Magento网站。 I'm looking to take any instance where "blog" is part of the URI, and make sure it's untouched by the myriad of other RewriteRules in Apache. 我正在寻找“博客”是URI一部分的任何实例,并确保它不受Apache中众多其他RewriteRules的影响。

As a few examples: 举几个例子:

http://www.example.com/blog/wp-admin/ http://www.example.com/blog/wp-admin/

http://www.example.com/blog/ http://www.example.com/blog/

http://www.example.com/blog/save-money-groceries-without-coupons/ http://www.example.com/blog/save-money-groceries-without-coupons/

...should all direct to the Wordpress site found under /blog/ ...都应直接转到/ blog /下的Wordpress网站

http://www.example.com/ http://www.example.com/

http://www.example.com/plumbing/faucets.html http://www.example.com/plumbing/faucets.html

http://www.example.com/about/family-history.html http://www.example.com/about/family-history.html

...should all direct to the Magento site that is currently found under the root directory ...都应直接指向根目录下当前存在的Magento网站

What is the best practice in writing the .htaccess file to achieve this result? 编写.htaccess文件以获得此结果的最佳实践是什么?

To redirect http://www.example.com/blog/wp-admin/ to http://www.blog.example.com/wp-admin/ you can add the following to the .htaccess file 要将http://www.example.com/blog/wp-admin/重定向到http://www.blog.example.com/wp-admin/您可以将以下内容添加到.htaccess文件中

RewriteEngine On
RewriteRule ^blog/(.*)$ http://www.blog.example.com/$1 [L,R=301]

I'm not an expert on setting up Apache servers but I think you want your WordPress install in a completely different folder to Magento and then use Alias in your .conf file. 我不是设置Apache服务器的专家,但我认为您希望将WordPress安装在与Magento完全不同的文件夹中,然后在.conf文件中使用Alias You can read about the Alias directive here . 您可以在此处阅读有关Alias指令的信息

For example in my Apache .conf files I have 例如在我的Apache .conf文件中

Alias /blog/ "/full/path/to/wordpress/htdocs/"

This way the folder /full/path/to/wordpress/htdocs/ has its own .htaccess and its own index.php - which is what you are going to want for running WordPress without jumping through hoops. 这样,文件夹/full/path/to/wordpress/htdocs/具有其自己的.htaccess和其自己的index.php这就是您要运行WordPress而又不会遇到麻烦的情况。

Remember to restart Apache if you update the .conf file. 如果更新.conf文件,请记住重新启动Apache。

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

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