Answer the question
In order to leave comments, you need to log in
Mod_rewrite and hosting?
Good afternoon friends.
Help who than can understand with a hoster. The client provided hosting, a certain Alkar.net where, judging by the help, nothing has changed since ten years, CGI is still successfully used, and so on.
When I started uploading a site that has .htaccess with some rules, everything became a 500 error, but I see this from time to time, especially on hosting France and Belgium, but it’s worth finding and commenting out some rule or adding some new one that they recommend and everything is working. But I began to try to find what the problem was this time I came across something that never bothered me.
The rule itself is very simple:
RewriteRule ^(?!admin/|css/|images/|inc/|js/|m/|pma/)(.+)$ index.php [L,QSA]
That is, everything that does not start with admin/|css/|images/|inc/|js/|m/|pma is transferred to index.php. This rule has been working for 4 years already and I have never touched it anywhere and there is nothing to touch here, it works on my test hosting, but this provider has everything in 500. He doesn't like "?!" that is, the denial of what comes next.
Friends, tell me how to be, everything works on this rule, nowhere without it.
Thanks for your advice and time.
Answer the question
In order to leave comments, you need to log in
If you are still interested, Apache versions before 2.0 do not support PCRE, but only POSIX regular expressions (http://httpd.apache.org/docs/2.0/new_features_2_0.html).
Negative assertion (?! this is a feature of PCRE, not POSIX regular expressions, and therefore does not work.
After all, Apache wrote that it cannot compile this regular expression.
Replace your line with these and it will work on old Apache (tested):
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/admin/.*
RewriteCond %{REQUEST_URI} !^/css/.*
RewriteCond %{REQUEST_URI} !^/images/.*
RewriteCond %{REQUEST_URI} !^/inc/. *
RewriteCond %{REQUEST_URI} !^/js/.*
RewriteCond %{REQUEST_URI} !^/m/.*
RewriteCond %{REQUEST_URI} !^/pma/.*
RewriteRule ^(.*) /index.php [L,QSA]
Code for if index.php is in the root. If not, change RewriteBase, the path to index.php and in each condition !^/insert_path/admin/.*
Is it possible to read the logs?
Is mod_rewrite enabled? If so, are RewriteRule directives allowed?
Try excluding folders using the RewriteCond directive. Your directive is using the PCRE regular expression feature, maybe that's the point.
You can replace it like this:
RewriteCond %{REQUEST_URI} !^/(admin/|css/|images/|inc/|js/|m/|pma/).*
RewriteRule ^(.*)$ index.php [L,QSA]
RewriteRule works, above rule is there and mod_rewrite is enabled. In general, the issue is removed, the hoster gave us a password for MySQL for the second day, which I told the client to use such hosting and we have already paid for the normal one.
Although, of course, this question is very interesting, as there was recently a note on Habré about .htaccess and I left messages there that different directives may be prohibited on different hostings.
Errors should be looked at in the logs, and not trying to guess the cause.
I found access to the logs, I already want to figure it out for myself. The error is as follows:
RewriteRule: cannot compile regular expression '^(?!admin/|css/|images/|inc/|js/|m/|pma/)(.+)$'
I will look for a solution.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question