gpt4 book ai didi

php - .htaccess 从 URL 中删除文件扩展名和变量

转载 作者:行者123 更新时间:2023-12-04 15:13:15 25 4
gpt4 key购买 nike

我知道这个问题已经被问过很多次了,但无论我怎么尝试,我的代码仍然无法正常工作。我有这个 .htaccess 文件,我想从此重定向我的代码:

example.com/news/articles.php?id=21&artName=Hello-World

为此:

example.com/news/articles/21/Hello-World

目前我的 .htaccess 文件中有这段代码:

Options -MultiViews
RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^news/articles/([\w-]+)/(.+) news/articles.php?id=$1&artName=$2 [QSA,L,NC]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule !\.php$ %{REQUEST_URI}.php [QSA,L]

这是该文章的 href 链接:

<a href="https://www.example.com/news/articles/21/Hello-World">Article</a>

每当我尝试转到该页面时。我收到“错误 404 - 未找到”页面。我是编辑 .htaccess 文件的新手,所以请让我知道我在代码中做错了什么,这样我就可以在我的链接中看到成功重写,谢谢。

最佳答案

您可以在您的 .htaccess 顶部尝试禁用 mod_spelling 选择:

<IfModule mod_speling.c>
CheckSpelling off
CheckCaseOnly off
</IfModule>

Options -MultiViews
RewriteEngine On

RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

RewriteRule ^(news/articles)/([\w-]+)/(.+) $1.php?id=$2&artName=$3 [QSA,L,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

This will disable multiple choice option.

Summary
Requests to documents sometimes cannot be served by the core apache server because the request was misspelled or miscapitalized. This module addresses this problem by trying to find a matching document, even after all other modules gave up. It does its work by comparing each document name in the requested directory against the requested document name without regard to case, and allowing up to one misspelling (character insertion / omission / transposition or wrong character). A list is built with all document names which were matched using this strategy.

关于php - .htaccess 从 URL 中删除文件扩展名和变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64810095/

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