Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I rewrite a subset of urls (/api/something)?
    primarykey
    data
    text
    <p>I have a .htaccess rule that basically points all access through one page, and I have PHP handling it from that point. So, no matter what directory it is in, it'll pass all URLs to this script.</p> <p>If my root was /project/ ( example.com/project/some/page/where ), /some/page/where would get redirected to @frontend.php</p> <pre><code>RewriteRule !\.(js|ico|gif|jpg|png|css|pdf|swf|doc)$ @frontend.php </code></pre> <p>I've reached a point however, where I want to be able to push a subset of pages through to a different handler, like so ( example.com/project/api/page/where, not example.com/project/some/api/where ):</p> <pre><code>RewriteRule ^/api?$ @api.php </code></pre> <p>Problem is, this does not work, no matter if this rule is above or below the other one. Can anyone suggest how I would be able to do this?</p> <p>I have also tried:</p> <pre><code>RewriteRule ^/api(/.*)? @api.php [L] RewriteCond %{REQUEST_URI} !/api RewriteRule !\.(js|ico|gif|jpg|png|css|pdf|swf|doc)$ @frontend.php [L] </code></pre> <p>And while this works in that <a href="http://example.com/project/api/page/where" rel="nofollow">http://example.com/project/api/page/where</a> doesn't get pushed to @frontend.php, it doesn't get it to @api.php, and produces:</p> <pre><code>[Wed Apr 18 10:46:12 2012] [error] [client 127.0.0.1] File does not exist: /www/project/api </code></pre> <p>EDIT:</p> <p>My latest attempt is:</p> <pre><code>RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^api(/.*)? @api.php [L] RewriteCond %{REQUEST_URI} ^api RewriteRule !\.(js|ico|gif|jpg|png|css|pdf|swf|doc)$ @frontend.php </code></pre> <p>The problem with this one is that if the URL starts with anything except api/, like ( example.com/project/test/page/where ) it throws the error: </p> <pre><code>[Sat Apr 21 10:50:13 2012] [error] [client 127.0.0.1] File does not exist: C:/xampp/www/projects/frame3/test </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload