RewriteCond: unknown flag 'QSA' - apache

When configuring Restler it suggests creating the following re-write rule:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
I have put this into a .htaccess file in root of my REST directory but I'm getting a 500 Server error when this rule is being fired. The error message the apache error log is:
[Wed Oct 10 10:39:30 2012] [alert] [client 127.0.0.1] /public/api/.htaccess: RewriteCond: unknown flag 'QSA'
[Wed Oct 10 10:39:30 2012] [error] [client 127.0.0.1] File does not exist: /public/favicon.ico
I assume the lack of a favicon.ico file can be ignored but I am concerned about the "unknown flag 'QSA'" error. I know very little about rewrite rules so any help there would be appreciated.
For those familiar with Restler, I am using 3.0.0rc2 (if that matters). Also it's worth pointing out that using the explicit call to index.php works so much as I then get a 404 JSON error response (a positive improvement) but as indicated above if I rely on the rewrite rule then I just get a 500 Server Error:
http://localhost/api/index.php/say/hi - WORKS (gives JSON 404 error)
http://locahost/api/say/hi - 500 SERVER ERROR

It doesn't look like the error has anything to do with the rules that you have:
/public/api/.htaccess: RewriteCond: unknown flag 'QSA'
which says that the QSA flag is an unknown flag for a RewriteCond, followed by a favicon.ico not found so I'm guessing that it's unrelated to requests into your REST directory.
If you had AllowOverride None, then your htaccess file is simply going to be outright ignored. There are different aspects of configuration options that can be overridden inside htaccess files, None means, htaccess cannot override any configurations, so it'll just get ignored.
The QSA flag isn't needed at all here. You only need it when you are rewritting the query string and want to append the original query string to the end. By default, the query string is appended anyways.

Interesting ... I was looking into my JSON 404 message and found this post:
Restler always returns not found
It not only solved my 404 error but also helped to fixed the 500 Server error. The only thing I needed to do was change the http.conf's AllowOverride to All.
I'd still be interested if anyone could tell me WHY this is happening but the this does now work.

Related

If URI is a file link then prepend with folder else rewrite with index.php

Dir stracture
- dist
- js
- css
- index.php
- .htaccess
I don't want to move index.php to /dist because the dist files are build by Vue.js and excluded from git and etc.
I'm trying to get this working for hours with help of Google and Apache docs but failing.
My .htaccess for now:
RewriteEngine On
RewriteRule ^(app|dict|ns|tmp)\/|\.ini$ - [R=404]
RewriteCond %{REQUEST_URI} .(css|js)$
RewriteRule ^(.*.(css|js))$ /dist/$1 [QSA,L]
RewriteRule ^ index.php [QSA,L]
It rewrites all needed requests to the index.php, but js and css throws an error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Apache logs:
[Fri Aug 16 23:10:06.973003 2019] [core:error] [pid 10716:tid 996] [client 127.0.0.1:2106] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
As the title says I want to prepend all the assets with \dist folder otherwise rewrite to index.php.
I looked at backtrace and this is what I've got after changes:
RewriteEngine On
RewriteRule ^(app|dict|ns|tmp)\/|\.ini$ - [R=404]
RewriteCond %{REQUEST_URI} ^(?!dist\/?).*.(css|js|map)$
RewriteRule ^((?!dist\/).*.(css|js|map))$ /dist/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
It works
The thing is
A RewriteRule loops when the target of the rule matches the initial rewrite pattern. For example, if you were to rewrite all URLs starting with "foo" to "foo.php", then "foo.php" would also get rewritten to "foo.php", and so on, forever.
You should look in the source if you ran in to this.

RewriteRule htaccess issue

i have live-cams.php file in root directory of my project and i try to rewrite link as /live-cams
RewriteRule ^live-cams ./live-cams.php [NC,L]
This rule throw
500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
also throw the same error when i try to open file /live-cams.php. Rule for index.php looks like to live-cams.php and it work well
RewriteRule ^home ./index.php [NC,L]
When i type friendly link as ^live-cams/ instead of ^live-cams it works.
Apache error log:
[Fri Aug 18 12:20:38.011915 2017] [core:error] [pid 14024:tid 1920] [client ::1:58474] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
Anyone know whats is wrong?
You need to use anchors in your regex pattenrs:
RewriteRule ^live-cams/? live-cams.php [NC,L]
RewriteRule ^home/?$ index.php [NC,L]
Otherwise live-cams is part of your original and rewritten URIs thus causing mod_rewrite to keep executing your rules until it hits LimitInternalRecursion count.

htaccess rewrite - 404 on existing file

So I have the following rewrite in an htaccess file:
RewriteRule ^([^/.]+)/?$ index.php?page=$1 [L]
Whenever I try to go to http://domain/index I get a 404, but when I try to go to http://domain/index. or even a non-existent page like http://domain/a, the rewrite works just fine and index.php var_dump()s the appropriate values.
The only code in index.php is var_dump($_GET);, so I know it's not a php issue.
Can someone explain to me what's wrong with my rewrite rule, and explain how to fix it?
EDIT:
I forgot I had error logging enabled. The error it keeps saving to error.log is:
[Sun Feb 24 21:01:18 2013] [error] [client 192.168.1.1] Negotiation: discovered file(s) matching request: /path/public_html/index (None could be negotiated).
By the error, it seems MultiViews is enabled.
You may try this at the top of the file:
Options +FollowSymlinks -MultiViews
Additionally, I suggest the following:
# Prevent loops
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule ^([^/]+)/? index.php?page=$1 [L]
MultiViews provides for Content Negotiation, best described here
When MultiViews is enabled (Options +MultiViews), the Content Negotiation module looks for files that match index, but .php files don't qualify for a match, so it fails with None could be negotiated. You can add .php handlers as matches using:
MultiviewsMatch Handlers Filters
as documented in MultiviewsMatch.

mod-rewrite remove folder name from url

I am using OJS and I have installed it inside a folder called "journals". I have created some journals there (for example "journal1", "journal2", etc).
Now I am getting paths like this: www.example.com/journals/index.php/journal1,
www.example.com/journals/index.php/journal2, etc.
What I want is to map www.example.com/journals/index.php/journal1
to looks like www.example.com/index.php/journal1 (removing the journal part from URL).
I can't move OJS to root because I have some other files there.
Here is the .htaccess file which I am using currently (it's in "journals" folder and giving me a 500)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^journals
RewriteRule ^(.*) /journals/$1 [L]
</IfModule>
Also Here is the error.log
[Fri Oct 12 22:16:45 2012] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
When you put those rules inside the htaccess file in your /journals directory, it's causing a rewrite loop. $1 never starts with journals because you're inside the journals directory, thus the rule keeps getting applied.
You'll need to put something like this in your htaccess file in your site-root, the / directory:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/journals
RewriteRule ^index\.php(.*)$ /journals/index.php$1 [L]

500 error while implementing MVC in apache server

I am bigginer to php and i was trying to implement Model-View-Controller in php i updated allow override to all and created a .htacess file and wrote the following quotes in it,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 {QSA,L}
but i gave me 500 error and i went straight to apache error log and got these errors:
[Mon Apr 09 01:18:36 2012] [alert] [client ::1] C:/wamp/www/.htaccess: Invalid command 'RewriteEngine', perhaps
misspelled or defined by a module not included in the server configuration
I googled and googled but cant find it, i just want to pass all the request to index.php file i watched a video on youtube it was working fine in his computer but not on mine, he told i should modify something in php.ini but i don't know whats that, if i write the following in .htacess:
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
and goto url that dont exists, then it is controlled by 404.php but it i tried to write the first script then i gives me 500 error every time... Previously i also tried to install zend framework but still there was same error....
I apologize for my language,,,
thanks in advanced... please help...
Is your rewrite module in apache enabled? You can enable it in httpd.conf file in your installation dir. If you are using windows just uncomment the rewrite module line and restart your apache.
You can google "enable apache rewrite" for more information.
You need to enable mod_rewrite. Either by 'a2enmod rewrite' or by adding manually to httpd.conf