我在使用查询字符串重写文件路径时遇到问题
我正在尝试获取如下所示的网址:
https://url.com/products/1_Samsung_Galaxy
并像这样重写对我的服务器的请求:
https:url.com/model.php?id=1&title=Samsung_Galaxy
这是我的 htaccess 到目前为止的样子:
RewriteEngine On
#rewrite no ending files to .php if file doesn't exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !products/
RewriteRule ^([^.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/products/([1-9]+)(.*)$ model.php?id=$1&title=$2 [NC,L]
使用当前配置,请求将发送到与 model.php 位于同一目录中的名为 products.php 的文件,但似乎位于不同的目录中,因为具有相对路径的 products.php 中引用的一些脚本文件会抛出异常它们包含的对象不存在的错误。
实际上,我的主要问题是我不知道 apache 语法或它是如何工作的,而且我很难找到可以了解 apache 的资源。由于某种原因,apache 文档没有太大帮助。如果有学习如何编写 apache 文件的好资源,我也很乐意查看。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号