RewriteCond: Bad flag delimitor in my .htaccess - .htaccess

I kinda need your help. I suddenly got website 500 error on my company's website. I have taken my complete code and put it through htaccesscheck.com.
It narrowed it down to line 290 in my .htaccess file.
The line is:
RewriteCond %{HTTP_USER_AGENT} !(android|blackberry9500|blackberry9530|cupcake|dream|incognito|iphone|ipod|mini|webOS|webmate|2.0 MMP|ASUS|AU-MIC|Alcatel|Amoi|Audiovox|AvantGo|BenQ|Bird|BlackBerry|Blazer|CDM|Cellphone|DDIPOCKET|Danger|DoCoMo|Elaine/3.0|Ericsson|EudoraWeb|Fly|HP.iPAQ|Haier|Huawei|IEMobile|J-PHONE|KDDI|KONKA|KWC|KYOCERA/WX310K|LG|LG/U990|Lenovo|MIDP-2.0|MMEF20|MOT-V|MobilePhone|Motorola|NEWGEN|NetFront|Newt|Nintendo Wii|Nitro|Nokia|Novarra|O2|Opera Mini|Opera.Mobi|PANTECH|PDXGW|PG|PPC|PT|Palm|Panasonic|Philips|Playstation Portable|ProxiNet|Proxinet|Qtek|SCH|SEC|SGH|SHARP-TQ-GX10|SIE|SPH|Sagem|Samsung|Sanyo|Sendo|Sharp|Small|Smartphone|SoftBank|SonyEricsson|Symbian|Symbian OS|SymbianOS|TS21i-10|Toshiba|Treo|UP.Browser|UP.Link|UTS|Vertu|WILLCOME|WinWAP|Windows CE|Windows.CE|Xda|ZTE|dopod|hiptop|htc|i-mobile|nokia|portalmmm|vodafone|ipad) [NC]
Which gives this error: RewriteCond: bad flag delimiters
As i am not very experienced in coding, i have not been able to detect the fault yet.
If there is anyone who can help me on this matter, it would be greatly appreciated.
-Jasper

Use:
RewriteCond %{HTTP_USER_AGENT} !"(android|blackberry9500|blackberry9530|cupcake|dream|incognito|iphone|ipod|mini|webOS|webmate|2.0 MMP|ASUS|AU-MIC|Alcatel|Amoi|Audiovox|AvantGo|BenQ|Bird|BlackBerry|Blazer|CDM|Cellphone|DDIPOCKET|Danger|DoCoMo|Elaine/3.0|Ericsson|EudoraWeb|Fly|HP.iPAQ|Haier|Huawei|IEMobile|J-PHONE|KDDI|KONKA|KWC|KYOCERA/WX310K|LG|LG/U990|Lenovo|MIDP-2.0|MMEF20|MOT-V|MobilePhone|Motorola|NEWGEN|NetFront|Newt|Nintendo Wii|Nitro|Nokia|Novarra|O2|Opera Mini|Opera.Mobi|PANTECH|PDXGW|PG|PPC|PT|Palm|Panasonic|Philips|Playstation Portable|ProxiNet|Proxinet|Qtek|SCH|SEC|SGH|SHARP-TQ-GX10|SIE|SPH|Sagem|Samsung|Sanyo|Sendo|Sharp|Small|Smartphone|SoftBank|SonyEricsson|Symbian|Symbian OS|SymbianOS|TS21i-10|Toshiba|Treo|UP.Browser|UP.Link|UTS|Vertu|WILLCOME|WinWAP|Windows CE|Windows.CE|Xda|ZTE|dopod|hiptop|htc|i-mobile|nokia|portalmmm|vodafone|ipad)" [NC]
With "
Or encode space as \. ex: 2\.0\ MMP

Related

Make URLs pretty with one line of htaccess

So I've had this issue for some time and originally I just dealt with it the long way around but that didn't work so I was hoping for a more solid solution.
My problem currently is that using the following code:
RewriteRule ^error/([a-zA-Z0-9-]+)/$ error.php?id=$1
error.php?id=404 becomes this:
/error/404/
Which is perfect. However if I add a new page which uses an id at the end, I have to add it in to my htaccess which is extra work and doesn't seem very good in terms of best practice.
I was hoping with one line I could have all sorts of combinations but it doesn't work.
I tried the following which resulted in a default 300 multiple request error.
RewriteRule ^/([a-zA-Z0-9-]+)/$ $1.php?id=$2
Any help please?
You can use this
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^([^/]+)/([^/]+)/$ /$1.php?id=$2 [L]
Example: /error/404/ will be rewritten to /error.php?id=404 if error.php exists
Note: maybe you'll have to disable MultiViews option (apache content negociation)
Options -MultiViews

.htaccess Redirect in case of 404

I have this line of .htaccess
This line is used to get images from another server.
RewriteRule ^resources/fabricantes(.*)$ http://mysecondserver.com/arq/pictures/fab$1
than, if I have the url: http://myserver.com/resources/fabricantes/fab_1.jpg
this image will be get from: http://mysecondserver.com/arq/pictures/fab/fab_1.jpg
The Problem:
In some cases, the image doesn't exists on mysecondserver.com, how can I redirect to a "image unavailable" image in this cases?
First think you need to understand that this rule can only work from mysecondserver.com host not from server.com.
On mysecondserver.com place this .htaccess in /arq/pictures/.htaccess:
RewriteEngine On
RewriteBase /arq/pictures/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ no-image.jpg [L]
On mysecondserver.com, you would have .htaccess checking for -f status of the REQUEST_FILENAME. It could send the user back to the first server, if necessary. The alternative is to explicitly list all known failures back on your first server, which is a lot of work for you (even if you have a complete list). There's no way for the first server to know if a file actually exists on the second server.

using mod_rewrite to strip out junk

We're seeing some really weird URLs in our logs and I've been told to start redirecting them.
I know of a couple of better ways to go about fixing this, but the boss wants it done this way. I apologize in advance.
We're seeing stuff like the following in our logs:
http://www.example.com/foo/bar/bla&ob=&ppg=&rpp=100&ob=&rpp=&ppg=&rpp=30&ppg=&ppg=1&rpp=10&rpp=50&ob=&ob=&ob=&rpp=40&ob=&rpp=5&rpp=30&rpp=&rpp=20&order_by=&results_per_pge=75
I've been told to 'toss some mod_rewrite rules in the .htaccess file' to take this and strip out all the ob, rpp, and ppg variables.
Now, I've found ways to strip everything out. And that wouldn't be too bad if I could leave the /foo/bar/bla in there. But I can't seem to do that. Basically, any help would be appreciated.
Try:
# strip out any params that's ob=, rpp= or ppg=
RewriteRule ^/?(.*)&ob=([^&]*)&(.*)$ /$1&$3 [L]
RewriteRule ^/?(.*)&rpp=([^&]*)&(.*)$ /$1&$3 [L]
RewriteRule ^/?(.*)&ppg=([^&]*)&(.*)$ /$1&$3 [L]
# if everything's gone, finally redirect and fix query string
RewriteCond %{REQUEST_URI} !&(ob|rpp|ppg)
RewriteRule ^/?(.*?)&(.*) /$1?$2 [L,R=301]
The problem here is that your URL:
http://www.example.com/foo/bar/bla&ob=&ppg=&rpp=100&ob=&rpp=&ppg=&rpp=30&ppg=&ppg=1&rpp=10&rpp=50&ob=&ob=&ob=&rpp=40&ob=&rpp=5&rpp=30&rpp=&rpp=20&order_by=&results_per_pge=75
has A LOT of ob=, rpp=, and ppg= in the URI. More than 10. That means you'll get a 500 internal server error if you use these rules against that URL. By default, apache has the internal recursion limit set to 10, that means if it needs to loop more than 10 times (and it will for the above URL), it'll bail and return a 500. You need to set that higher:
LimitInternalRecursion 30
or some other sane number. Unfortunately, you can't use that directive in an htaccess file, you'll need to go into server or vhost config and set it.

need .htaccess RewriteRule advise

I've looked around for an answer to this, no luck.
What i want to do is replace
http://localhost/mysite/superv/something with
http://localhost/mysite/superv/?p=something
Here's the best formula I came up with since yesterday:
RewriteEngine On
RewriteBase /mysite/
RewriteRule ^(superv/)([^\?/]+)$ $1\?p=$2 [NC]
Yet it's not working.
I think the "RewriteBase" thingy has nothing to do with the problem because this line is working like a charm:
RewriteRule ^(javascripts/main\.js)$ $1\.php [NC]
Edit: Right Rekire, that was a mistake while copying and pasting the code. I've fixed the question now.
Edit2: Here's the error that appears in apache logs:
[Tue Mar 20 20:26:01 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.
I'm guessing the problem is "looping" and I quote:
Looping occurs when the target of a rewrite rule matches the pattern.
This results in an infinite loop of rewrites
This appears to be working for me.
RewriteRule ^(superv/)([^\?/]+)$ $1?p=$2 [R,NC]
Remove the R, if you want to do an internal redirect.
For some reason, this formula worked (internal redirect):
RewriteRule (.*)(superv/)?(.*) $1$2index.php?p=$3 [NC,QSA]
It seems to have broken the "infinite loop".

rewriteRule for URL path not working correctly

I need help with a URL problem I've encountered with a rewriteRule.
What I need it to do is following: example.com/en/page/page/
At the moment the following works fine: example.com/en/page/
But once it goes like "example.com/en/page/page/" I receive a 404 - page not found error even if the page in fact is located in the serverfiles.
The clue here is that I use a variable in the /en/ part of the URL (multilanguage system) and it seems that I cannot figure out how to get it to work with that included.
At the moment I have the following rewriteRule in my .htaccess file.
RewriteRule ^([^/]*)/([^/]*)/?$ index.php?lang=$1&uri=$2 [L]
Do any of you have a clue on what might work?
Best regards,
PureDarkness
You don't include anything behind the second /. You could try:
RewriteRule ^([^/]*)/(.*)$ index.php?lang=$1&uri=$2 [L]
And you can add [QSA] if you also need to get the parameters.

Resources