gpt4 book ai didi

apache - 将 RewriteCond 与 %{REQUEST_URI} 一起用于 mod_rewrite

转载 作者:行者123 更新时间:2023-12-05 01:01:54 24 4
gpt4 key购买 nike

我想要网址:

http://domain.com/category/subcategory/title

指向:

http://domain.com/posts/category/subcategory/title.php

我的 .htaccess 文件如下所示:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !^.+
#RewriteCond post/%{REQUEST_URI}.php -f
RewriteRule ^(.*)$ post/$1.php [L]

但是当我取消注释上面的行时它不起作用。

我试过了:

RewriteCond /post/%{REQUEST_URI}.php -f
RewriteCond post/%{REQUEST_URI}.php -f
RewriteCond post%{REQUEST_URI}.php -f

这些都不起作用。我做错了什么?

还有调试这些规则的简单方法吗?比如控制台日志变量之类的?

最佳答案

-f 检查需要完整的文件系统路径。您可以使用 %{DOCUMENT_ROOT} 变量来做到这一点:

RewriteEngine on
RewriteBase /

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

关于apache - 将 RewriteCond 与 %{REQUEST_URI} 一起用于 mod_rewrite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38998802/

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