5

我正在尝试让 FuelPHP 在我的服务器上工作。我无权将 .htaccess 文件用于 RewriteRule。但是,我的主机允许我指定 httpd.conf 文件的一部分。

以下适用于我想要的:

<Directory /Applications/XAMPP/xamppfiles/htdocs/sandbox/username/public>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</Directory>

但是,我需要它不仅仅用于其中的“用户名”。如何在此目录中使用通配符,以便它适用于一次性解决方案的任何“用户名”值?

我在apache 手册上找到了这个建议,但我不确定如何让它与RewriteRule.

尝试了以下但没有奏效:

<Directory /Applications/XAMPP/xamppfiles/htdocs/sandbox/*/public>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</Directory>

请帮忙!

4

2 回答 2

8

你很接近 apache 手册:

<Directory /Applications/XAMPP/xamppfiles/htdocs/sandbox/*/public>

<Directory ~ "/Applications/XAMPP/xamppfiles/htdocs/sandbox/.*/public">
于 2012-10-04T01:05:11.713 回答
1

我们发现这条消息解决了我们遇到的问题,但没有提供真正的解决方案:如何在使用通配符的目录指令中使用 apache2 mod_rewrite?

我们最终使用了以下解决方案:

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d

RewriteRule ^(/sandbox/([^/]*)/public/.*)$ /sandbox/$2/public/index.php?$1 [PT,QSA]

必须添加“PT”,因为它通常隐含在目录块中,并告诉它将目标路径视为 URI 而不是文件路径(这将不起作用,因为它没有获取完整的本地路径) . QSA 标志只是确保您的 index.php 收到最初提交的所有信息。

于 2012-02-09T17:15:01.777 回答