php - .htaccess 重写托管在 Bitnami/EC2 上的 Wordpress 主机

标签 php wordpress .htaccess ubuntu

我在 Amazon EC2 上安装了一个 Bitnami Ubuntu Wordpress 实例。
wordpress.conf Bitnami 实例上的文件就像一个 htaccess 文件。

目录结构如下:

/opt/bitnami/apps/wordpress/htdocs/index.php
wordpress.conf文件包含
Alias /wordpress/ "/opt/bitnami/apps/wordpress/htdocs/"
Alias /wordpress "/opt/bitnami/apps/wordpress/htdocs"

<Directory "/opt/bitnami/apps/wordpress/htdocs">
    Options Indexes MultiViews +FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    RewriteEngine On
    RewriteBase /wordpress/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
</Directory>

# Uncomment the following lines to see your application in the root
# of your URL. This is not compatible with more than one application.
#RewriteEngine On
#RewriteRule ^/$ /wordpress/ [PT]

这使得博客出现在这个 URL 上

http://ec2instance.com/wordpress/

我希望它是(包括查看单个帖子时):

http://ec2instance.com/blog/

http://ec2instance.com/blog/post-number-1

http://ec2instance.com/blog/post-number-2

ETC

有人知道如何进行此更改吗?

最佳答案

在该文件中,您将需要更改:

Alias /wordpress/ "/opt/bitnami/apps/wordpress/htdocs/"
Alias /wordpress "/opt/bitnami/apps/wordpress/htdocs"


Alias /blog/ "/opt/bitnami/apps/wordpress/htdocs/"
Alias /blog "/opt/bitnami/apps/wordpress/htdocs"

随着这一变化,apache 将在 /blog 中提供 wordpress。 .

然后,您还需要更改该文件中的重写规则(因为新的 url 将使用 /blog 而不是 /wordpress )。
RewriteBase /wordpress/
RewriteRule . /wordpress/index.php [L]


RewriteBase /blog/
RewriteRule . /blog/index.php [L]

最后,您还需要修改 wp-config.php文件(在 apps/wordpress/htdocs 中)确保 WP_SITEURLWP_HOME网址指向 /blog .
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/blog');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/blog');

关于php - .htaccess 重写托管在 Bitnami/EC2 上的 Wordpress 主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10163270/

相关文章:

php - 为什么 array_values 比 foreach 更好?

php - 通过php准备语句插入mySql失败

php - 更改 WooCommerce 我的帐户客户订单的排序

regex - 如何防止文件被直接 URL 访问?

php - 允许在本地主机上自签名 PHP? (禁用 SSL?)

php - PDO:找不到驱动程序 php/mysql

PHP - 递归多维数组迭代器

php - 将类添加到 Wordpress 图像 <a> anchor 元素

javascript - 推迟 wordpress 插件 css/script 好不好

apache - 通过 puppet 启用 .htaccess 文件