【问题标题】:Wildcards with Apache Directory and RewriteRule?Apache Directory 和 RewriteRule 的通配符?
【发布时间】:2012-03-01 11:31:53
【问题描述】:

我正在尝试让 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 manual 上找到了这个建议,但我不确定如何让它与RewriteRule 一起使用。

尝试了以下方法,但没有成功:

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

请帮忙!

【问题讨论】:

    标签: unix apache fuelphp


    【解决方案1】:

    我们发现这条消息解决了我们遇到的问题,但没有提供真正的解决方案:How to use apache2 mod_rewrite within a Directory directive that uses wildcards?

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

    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 获得了最初提交的所有信息。

    【讨论】:

      【解决方案2】:

      你对 apache 手册很了解:

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

      <Directory ~ "/Applications/XAMPP/xamppfiles/htdocs/sandbox/.*/public">
      

      【讨论】:

      • 你能说出这个语法有什么问题吗?我收到禁止消息: Alias /salt "/var/cache/salt/master/minions/.*/files" Options MultiViews FollowSymLinks要求所有授予的
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-06
      • 1970-01-01
      • 2017-09-24
      • 1970-01-01
      • 1970-01-01
      • 2012-07-02
      相关资源
      最近更新 更多