【问题标题】:Rewrite Rule in .htaccess not working With MAC OS.htaccess 中的重写规则不适用于 MAC OS
【发布时间】:2023-03-17 00:37:02
【问题描述】:
嗨,朋友们,我用 PHP 为我的网站编写了重写规则,它在 windows 和 Linux 操作系统上运行良好但是我当时把这个项目移到 MAC OSX 是出错并且没有正确重写
.htaccess 文件代码如下
RewriteEngine On
RewriteBase /ProjectName
RewriteRule uploads/(.*) uploads/$1 [L]
RewriteRule css/(.*) css/$1 [L]
RewriteRule libs/(.*) libs/$1 [L]
RewriteRule js/(.*) js/$1 [L]
RewriteRule images/(.*) images/$1 [L]
RewriteRule Files/(.*) Files/$1 [L]
RewriteRule API/(.*) API/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule (.*)$ index.php?module=$1 [L]
RewriteRule (.*)/(.*)$ index.php?module=$1&action=$2 [L]
RewriteRule (.*)/(.*)/(.*)$ index.php?module=$1&action=$2&id=$3 [L]
需要您的帮助
谢谢Guyzzz...
【问题讨论】:
标签:
php
macos
apache
.htaccess
【解决方案1】:
不知道你是如何让它在任何操作系统上工作的,因为最后一组规则永远不会被应用。
首先,您的 3 个条件仅适用于紧随其后的规则,因此仅适用于 RewriteRule (.*)$ index.php?module=$1 [L]。这意味着最后两条规则没有条件,恰好是OK,因为它们无论如何都不会被使用。 RewriteRule (.*)$ index.php?module=$1 [L] 规则的模式匹配所有内容,因此最后两条规则是多余的。你可能追求的是:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule (.*)/(.*)/(.*)$ index.php?module=$1&action=$2&id=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule (.*)/(.*)$ index.php?module=$1&action=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule (.*)$ index.php?module=$1 [L]