cPanel 上 Django 站点子目录中的 WordPress 博客

问题描述 投票:0回答:1

我在 StackOverFlow 上浏览了几篇类似的帖子,但我无法让它工作。我想要实现的是用 WordPress 加载任何包含 /blog/ 的 url。我已将 WordPress 实例移至名为 blog 的文件夹(在 public_html 内),并且当 Django 实例未使用 public_html 中的此 .htaccess 文件激活时,它可以正常加载。我的博客文件夹中没有 .htaccess 文件。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blog/$1
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^(/)?$ blog/index.php [L] 
</IfModule>

我还将数据库中的 WordPress URL 和站点地址更改为 mysite.com/blog/ 并使用 https://

当我激活 Django 实例时,我将 .htaccess 文件更改为以下内容。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^/blog/
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com/blog/$
RewriteRule . /blog/index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [L]
</IfModule>

# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/usr/mysite.com"
PassengerBaseURI "/"
PassengerPython "/home/usr/virtualenv/mysite.com/3.11/bin/python"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END

# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION BEGIN
<IfModule Litespeed>
SetEnv DEBUG False
etc...
</IfModule>
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION END

我尝试了这个 .htaccess 文件的不同变体,有时我让它间歇性地加载,但有时图像、样式表和其他所有内容都丢失了,有时它加载了,然后我无法进入 mysite/blog/wp-admin由于重定向太多。

django wordpress .htaccess
1个回答
0
投票

这是其他想要执行此操作的人的解决方案(感谢克里斯的提示)。

# if the Apache module mod_rewrite is enabled on the server then run the rules inside this block
<IfModule mod_rewrite.c>

# activate the Apache mod_rewrite engine
RewriteEngine On

# set the base URL for relative rewrite rules. 
# specifies that the base URL for rewriting is the root directory (/).
RewriteBase /

# if url contains /blog/ then load /blog/index.php. 
# [L] indicates that this is the last rule to be processed if url contains /blog/
RewriteCond %{REQUEST_URI} /blog/
RewriteRule . /blog/index.php [L]

# Serve other requests with Python
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [L]
</IfModule>

如果这不适合您,您可以尝试将以下内容添加到 /blog/ 文件夹内的 .htaccess 文件中。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} /blog/
RewriteRule . /blog/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blog/$1
RewriteRule ^(/)?$ index.php [L] 
</IfModule>
© www.soinside.com 2019 - 2024. All rights reserved.