导航到不属于 Django 应用程序一部分的链接会引发 404 错误

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

我在“mydomain.com”上运行一个 WordPress 站点,并在 mydomain.com/portal 上安装了 whmcs。一切都很好。我最近摆脱了 WordPress 安装并在 mydomain.com 上建立了一个 Django 网站。 mydomain.com/portal 上的 WHMCS 安装仍然存在。

但问题是:

  • 访问 mydomain.com/portal 出现 404 错误
  • mydomain.com/portal/admin 也是如此(404 错误)

如果我访问 mydomain.com/portal/index.php 或 mydomain.com/portal/login,页面就会加载

我当前在 mydomain.com 中的 .htaccess 文件:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Header always set Content-Security-Policy "upgrade-insecure-requests;"


# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/user/mydomain.com"
PassengerBaseURI "/"
PassengerPython "/home/usr/virtualenv/mydomain.com/3.9/bin/python"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION BEGIN
<IfModule Litespeed>
</IfModule>
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION END

# Newly added text below here, in order to troubleshoot CSS not showing up
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^static/(.*)$ /home/usr/mydomain.com/staticfiles/$1 [QSA,L,NC]
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^media/(.*)$ /home/usr/mydomain.com/blog_images/$1 [QSA,L,NC]
</IfModule>


<FilesMatch "\.(?i:ico|flv|jpg|jpeg|png|gif|js|css)$">
    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresDefault "access plus 1 month"
    </IfModule>
    FileETag MTime Size
</FilesMatch>

我尝试添加以下内容,但没有帮助。

重写引擎开启 RewriteCond %{REQUEST_URI} !^/portal/ RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 标头始终设置 Content-Security-Policy“upgrade-insecure-requests;”

我正在尝试让 whmcs 安装像以前在 mydomain.com/portal 上一样加载,而不必链接到 index.php

django .htaccess url-routing whmcs
1个回答
0
投票

您已从 WordPress 网站转换为 Django 网站,.htaccess 规则可能需要进行一些调整以适应新设置。 这是 .htaccess 文件的修订版本,它应该正确地将请求定向到 WHMCS 安装:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

# Redirect requests to WHMCS installation
RewriteRule ^portal(/.*)?$ /portal/index.php [L]

# Your existing rules below
Header always set Content-Security-Policy "upgrade-insecure-requests;"

# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/user/mydomain.com"
PassengerBaseURI "/"
PassengerPython "/home/usr/virtualenv/mydomain.com/3.9/bin/python"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION BEGIN
<IfModule Litespeed>
</IfModule>
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION END

# Newly added text below here, in order to troubleshoot CSS not showing up
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^static/(.*)$ /home/usr/mydomain.com/staticfiles/$1 [QSA,L,NC]
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^media/(.*)$ /home/usr/mydomain.com/blog_images/$1 [QSA,L,NC]
</IfModule>

<FilesMatch "\.(?i:ico|flv|jpg|jpeg|png|gif|js|css)$">
    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresDefault "access plus 1 month"
    </IfModule>
    FileETag MTime Size
</FilesMatch>

“RewriteRule ^portal(/.*)?$ /portal/index.php [L]”应该将所有到 /portal 的请求重定向到 /portal/index.php,允许 WHMCS 在内部处理路由以前做过。

© www.soinside.com 2019 - 2024. All rights reserved.