【问题标题】:Cannot redirect to a newly created page in php无法重定向到 php 中新创建的页面
【发布时间】:2020-04-05 22:43:59
【问题描述】:

您好,我正在尝试重定向到我使用标头函数在现有项目中创建的 php 文件,但它不起作用,结果我得到 404 未找到。

这是我写的那一行:

header('Location:payme.html');

当我对现有页面执行相同操作时,例如 profile.php,如下所示:header('Location:profile.html');

profile.php 和 payme.php 在同一个文件夹中

当我使用包含功能时,它可以工作:include BASE.'view/payme.php';

我认为问题出在 .htaccess 文件中,可能有规则阻止它。

这是 .htaccess 文件:

<IfModule mod_headers.c>
    Header set Referrer-Policy "same-origin"
    Header always set X-Content-Type-Options "nosniff"
    Header set X-XSS-Protection "1; mode=block"
    Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPS
    #Header set Content-Security-Policy "..."
</IfModule>


# -- DEFAULTS --
AddDefaultCharset UTF-8
DefaultLanguage fr

Options -Indexes +FollowSymlinks


# -- DENY ACCESS --
<FilesMatch "^(\.htaccess)$">
order allow,deny
deny from all
</FilesMatch>
<FilesMatch "^(\.htpasswd)$">
order allow,deny
deny from all
</FilesMatch>

# -- ERROR REDIRECTIONS --
ErrorDocument 400 /error400.html
ErrorDocument 403 /error403.html
ErrorDocument 404 /error404.html
ErrorDocument 405 /error405.html
ErrorDocument 500 /error500.html
ErrorDocument 501 /error501.html
ErrorDocument 502 /error502.html
ErrorDocument 503 /error503.html
ErrorDocument 504 /error504.html
ErrorDocument 505 /error505.html

RewriteEngine On



# -- ERROR PAGE ---
RewriteRule ^error([0-9]{3})\.html$ /error.php?code=$1 [L]

# -- FAKE ACCES DENYING ---
RewriteRule ^controller/(.+\.php)?$ /error404.html
#RewriteRule ^cron/(.+)?$ /error404.html
RewriteRule ^datas/(.+)?$ /error404.html
RewriteRule ^email/(.+)?$ /error404.html
RewriteRule ^external/(.+)\.php?$ /error404.html
RewriteRule ^external/php/(.+)$ /error404.html
RewriteRule ^model/(.+\.php)?$ /error404.html
RewriteRule ^params/(.+)?$ /error404.html
RewriteRule ^trustee/(.+\.php)?$ /error404.html
RewriteRule ^view/(.+\.php)?$ /error404.html


# -- SITE PAGES ---
RewriteRule ^(.+)\.html$ /index.php?htaccess_url=$1&%{QUERY_STRING} [L]

任何建议都会有所帮助,谢谢。

【问题讨论】:

  • 从您尝试重定向的页面到 payme.html 的路径是什么?这是您必须在 Location 指令中使用的路径。
  • 是payme.php还是payme.html?
  • 路径是Base.'view/payme.php"
  • 是一个php文件,里面有html代码
  • 您必须从外部用户的角度指定位置。确保这首先有效。 http://yourdomain/view/payme.php。或http://yourdomain/???/payme.php。代替 ???带有您的 payme.php 的路径。然后使用完全相同的路径指定您的位置。

标签: php header include


【解决方案1】:

通过在主控制器文件 index.php 中添加创建的页面名称解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-24
    • 2015-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    相关资源
    最近更新 更多