gpt4 book ai didi

apache - 如何为 GET 请求正确配置 Apache 重写规则?

转载 作者:行者123 更新时间:2023-12-04 00:51:38 24 4
gpt4 key购买 nike

当我尝试创建一个用户友好的 URL 时遇到以下问题,它返回 500 错误。

没用

RewriteEngine On
RewriteRule ^page/(.+)$ /page.php?type=$1 [L]

仅当我更改脚本名称时才有效

RewriteRule  ^page/(.+)$   /change-page.php?type=$1   [L]

有什么方法可以保留重定向到页面的 page.php 吗?谢谢

这里是完整的 .htaccess 配置

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# For LocalHost !.php
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTP_HOST} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=::1

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=302,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

RewriteRule ^page/(.+)$ /page.php?type=$1 [L]

最佳答案

试试这些规则:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

# For LocalHost !.php
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTP_HOST} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=::1
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[?\s] [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/([\w-]+)/?$ page.php?type=$1 [L,QSA,NC]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

关于apache - 如何为 GET 请求正确配置 Apache 重写规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65975390/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com