【问题标题】:.htaccess get variable redirect resulting in 500 internal server error.htaccess 获取变量重定向导致 500 内部服务器错误
【发布时间】:2020-11-25 04:57:54
【问题描述】:

我已阅读与此主题相关的其他帖子,但仍未找到我的解决方案。

我的.htaccess如下:

RewriteEngine On
Options +FollowSymLinks

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R]

ErrorDocument 404 https://website.com/page/404

# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

RewriteCond %{THE_REQUEST} ^.*/index
RewriteRule ^(.*)index /$1 [R=301,L]

# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^profile/([0-9a-zA-z_-]+) profile.php?username=$1 [L,QSA,NC]

每当我导航到 https://website.com/page/profile/name/ 时,我都会收到 500 内部服务器错误。

其他条件似乎工作正常,但特别是这个条件不是。

【问题讨论】:

  • 您的 htaccess 文件是否位于 /page 目录中?
  • @AmitVerma 它位于 public_html 下
  • @AmitVerma 直接位于 public_html 下我的意思是说,页面是 public_html 的直接子级
  • @AmitVerma 我已经重写了另一个 .htaccess 并将其放在页面目录中。此 .htaccess 仅包含与配置文件有关的行。这使页面正常工作,但是,它使每个其他页面都成为 404 错误。知道为什么会这样吗?

标签: php .htaccess server-error


【解决方案1】:

这是行不通的:

RewriteRule ^profile/([0-9a-zA-z_-]+) profile.php?username=$1 [L,QSA,NC]

你必须用这个来定义变量:(.*)

RewriteEngine on
RewriteBase "/"
RewriteCond %{HTTP_Host}          "!^$" [NC]
RewriteRule "^profile/(.*).php$"   "profile.php?username=$1"       [NC,L,QSA]

之后,您可以检查正则表达式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-30
    • 2014-01-11
    • 1970-01-01
    相关资源
    最近更新 更多