Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildcards with Apache Directory and RewriteRule?

I'm trying to get FuelPHP to work on my server. I don't have access to use .htaccess file for RewriteRule. However, my host has allowed me to specify a part of the httpd.conf file.

The following works for what I want:

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

However, I need it to work for more than just "username" in there. How can I use wildcards with this Directory so that it works for any values of "username" for a one-time solution?

I found this advice on the apache manual, but I'm not sure how to get it to work with the RewriteRule.

Tried the following but it didn't work:

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

Please help!

like image 247
Nate Radebaugh Avatar asked Feb 08 '12 23:02

Nate Radebaugh


2 Answers

You were close with the apache manual:

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

to

<Directory ~ "/Applications/XAMPP/xamppfiles/htdocs/sandbox/.*/public">
like image 96
vol7ron Avatar answered Oct 20 '22 05:10

vol7ron


We found this message that addressed the problem we had, with no real solution provided: How to use apache2 mod_rewrite within a Directory directive that uses wildcards?

We ended up using the following solution:

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]

The "PT" had to be added, as it is normally implied within directory blocks, and tells it to treat the target path as a URI instead of as a file path (which won't work since it's not getting the full local path). The QSA flag just makes sure your index.php gets handed all the information originally submitted.

like image 28
Nate Radebaugh Avatar answered Oct 20 '22 04:10

Nate Radebaugh