When asking regex questions, always add the tag for the specific programming language or tool (e.g., Perl, Python, or Java; vi, emacs, or ɢɴᴜ grep; etc.) you are using.

learn more… | top users | synonyms

4
votes
4answers
2k views

nginx rewrite base url

I would like the root url http://www.example.com to redirect to http://www.example.com/something/else This is because some weird WP plugin always sets a cookie on the base url, which doesn't let ...
1
vote
0answers
158 views

Nginx equivalent to lighttpd “evhost.path-pattern”

I'm setting up a new server for my personal stuff. On the old box I've used lighttpd for almost two years now. I've read a bit about it and most people tend to switch to nginx since it's development ...
2
votes
1answer
292 views

Regular expression not working on Powershell

Background: I need to match a multiline pattern(?) in a C# source file. The regular expression will be manipulate by Powershell. I have tested and it works on RegexBuddy (with the Dot Matches ...
4
votes
1answer
712 views

Ack search for literal strings [closed]

I am sick of having to escape things when I want to search for part of an html tag. How can I ack search for exactly what I type without having to escape stuff? e.g. ack-grep 'console.log(foo' I ...
2
votes
1answer
131 views

Recursively search and replace the contents of multiple file types

I have thousands of web files(*.php, *.htm, *.html, etc) that contain an absolute path(http://site.com/sites/etc). I need to scan a directory and all subdirectories for the various file types and ...
1
vote
1answer
233 views

RewriteRule mp3 to php

I want to rewrite all .mp3 files to a php file. And I dont want to pass on the path so http://localhost/somepath/feb.mp3 http://localhost/feb.mp3 shouldn't do any difference. I came up with: ...
0
votes
1answer
334 views

Modify swatch conf files to match multiple lines below a match

We use swatch for reading PHP logs and email them to us. Currently it emails one single line of the error, but fails to match the next few lines of stack trace. For example: for log file like this: ...
1
vote
1answer
173 views

How to redirect all subdomains do one domain in Apache config file without specifying domain name?

I want to make general rule for all my domains, so I don't have to specify each of them individually. I have these two lines in my Apache config file: RewriteCond %{HTTP_HOST} ^domain\.com ...
0
votes
0answers
297 views

How can i test for an environment variable in a RewriteCond

Is there a way to put an environment variable in the condPattern part of a RewriteCond? Here is what i tried: RewriteCond %{REQUEST_URI} /%{ENV:ALIAS}/(js|css|img).* RewriteRule (.*) - [L,NS] But ...
3
votes
1answer
2k views

Fail2Ban SASL Filter Misses Failed Logins

I am using fail2ban on my mail server. I discovered this morning that there were some 5000 failed login attempts (in the course of 1 hour) via SMTP that didn't get picked up by my sasl filter. Here ...
0
votes
2answers
321 views

How do I delete a matching line, the lines above and those below in the section?

In nagios config define service{ use generic-service host_name xxx.xxx.com service_description xxx Status check_command ...
0
votes
1answer
200 views

Mod_rewrite excluding files/directories but including .php files

The traditional mod_rewrite for routing is as follows: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [L] ...
0
votes
2answers
603 views

fail2ban regex to catch dovecot log entry?

Am trying to write a fail2ban regex that catches anyone who tries the user-id "administrador". For example, this log entry: Jan 2 09:55:01 mail2 dovecot: pop3-login: Disconnected: ...
3
votes
3answers
1k views

Nagios not accepting regex in command

I have this command defined: define command{ command_name check_http_sane command_line $USER1$/check_http -H $HOSTNAME$ -r "HTTP/1.1 (200|301|302|303|304|307|401|418|426)" } When I run it manually ...
2
votes
2answers
63 views

Get Apache2.2 to hide Microsoft documents that are being edited?

I have a htdocs directory where I am serving a few Microsoft Word documents. When someone is editing a document, the name of the document changes to look like something like this: ...
0
votes
2answers
3k views

How can I count instances of a regex match in a log file using PowerShell?

I have a very large log file in which I need to count the occurrences of all the variations of a particular string; that is: There are a large number of file IDs that appear in the format AA000####. ...
0
votes
1answer
193 views

.htaccess ModRewrite when moving web root content into subdirectories?

I'm cleaning up and rearranging the files on my server (basic shared hosting situation) and am digging into .htaccess to do so. I'm moving the content I had in my web root into the subdirectory of ...
1
vote
1answer
449 views

RewriteRule: cannot compile regular expression. Version support?

I'm running an Ubuntu 10.04 LTS, Apache version 2.2.14. On httpd.conf I've a rewrite rule that look like this: RewriteRule (*UTF8)^/users/([^/])([^/]+)/(.*)$ /users/$1/$2/$1$2/$3 [L] The idea ...
2
votes
3answers
219 views

How do I find this string?

I'm trying to match these file names with the find command: 4702011-10-21CR719557-R85262-ALPHA.jar 4702011-10-21CR719557-R85262-BETA.jar I'm reasonable familiar with Java-Perl regex syntax. ...
0
votes
2answers
333 views

Nginx: wild card dns redirect URL to subdomain

I'm trying to redirect the following URL Http://example.com/category/something To redirect to Http://something.example.com/category/something Where "something" could be anything. I've already ...
2
votes
2answers
751 views

fail2ban regex that uses less CPU?

Using fail2ban, I want to ban these spammers who are sending to a spamtrap address: Oct 27 09:04:22 si68 postfix/smtpd[3240]: NOQUEUE: reject: RCPT from unknown[117.197.114.222]: 550 5.7.1 ...
0
votes
1answer
1k views

Apache htaccess RewriteRule to remove trailing slash; infinite loop?

I use the following in .htaccess (mod_rewrite) to remove the trailing slash from my URLs: RewriteRule ^([a-z0-9_-]+)/$ $1 [L,NC,R=301] Of course, since the character class doesn't match a slash, ...
3
votes
2answers
2k views

How can I route some emails to a script in Postfix?

How do I route all emails directed to user-*@example.com (i.e. user-1234@example.com) to a pipe command in Postfix? The idea is to create craigslist-style anonymization by assigning dynamic email ...
1
vote
2answers
4k views

How to exclude files from TAR archive using regular expressions?

I have a simple question, yet I can't find or solve the answer. I want to make a tar archive, but I want to exclude some files from it using regular expression. Example of the file to exclude is ...
1
vote
1answer
847 views

nginx regex characters that require quoting?

So I was configuring nginx today and I hit a weird problem. I was trying to match a location like this: location ~ ^/([0-9]+)/(.*) { # do proxy redirects } ...for URLs like ...
1
vote
2answers
986 views

Postfix virtual domains: how to accept all subdomains except for two?

Assuming my Postfix server serves the domain example.com, I want it to accept mail for all the subdomains of example.com except for mail.example.com and in.example.com. At first I've tried using a ...
3
votes
2answers
513 views

egrep matching group not printing?

I'm trying to create a bash script that will grep lines from a file using egrep. I've created the regex that should group the information I want, the issue is trying to get the output. I've been ...
2
votes
1answer
621 views

Weird 404 issue with nginx 's.png'

This URL is invalid: http://mysite.co.uk/assets/images/whymysite/viewoptions.png However, if I replace the 's' at the end before .png, with ANY other standard character (that I've tried so far, it ...
4
votes
3answers
4k views

Regex for sed to grab multiple lines or a better way?

I'm creating a script that connects to a server and dumps the output to a tempfile. I want to use sed in the script to grab specific information from the temp file. The output would always have the 80 ...
0
votes
1answer
144 views

Apache redirect to another domain all URLs, except for ones starting with substring

Can anyone help me achieve a redirect in Apache from http://subdomain.example.com/ to http://example.com/ for all URLs, EXCEPT the ones starting with "files/"? Thank you
3
votes
3answers
4k views

nginx rewrite append a parameter at the end of an url

I need to configure my reverse proxy so that the following parameter will be added at the end of the url: &locale=de-de This almost works: rewrite ^(.*)$ $1&locale=de-de break; However, the ...
5
votes
2answers
2k views

rsync: How to exclude Dotfiles only in topmost directory?

When performing backups under Bash with rsync, I'm trying to exclude all dotfiles and hidden directories in the top directory, but not those in otherwise targeted directories. For example: /copyme.c ...
2
votes
1answer
538 views

Why does my SetEnvIfNoCase directive does not match requested URI?

I'm attempting to set up Apache such that various error pages display with headers/footers appropriate to the context of the error. If the user was requesting a corporate page, I want to show the ...
0
votes
2answers
438 views

How to use RegEx for mod_security

I have a directory/site set-up like this on my Apache/2.2.19 (Win32) Server using mod_security + core ruleset/2.2.1 /website1/login.php /website2/login.php /website3/login.php /websiteN/login.php ...
1
vote
2answers
3k views

apache locationmatch negative regex

I'm trying to expose a location through Apache. Normally, I have this block in my vhost that says <Location /> AuthType Basic AuthUserFile /web/.htpasswd AuthName "Test Site" ...
0
votes
2answers
122 views

grep pattern matching for case insensitivity

I wanted to write a grep function to show me all listening ports on my host. I know how to do it by using the -i function in grep : netstat -a |egrep -i 'listen' But now I wanted to write it in ...
1
vote
2answers
138 views

weird apache rewrite regex

I'm in the process of migrating a setup from apache to nginx. In this process I've come across this rewrite rule in an .htaccess file: RewriteRule ^/?(?:(?!one|two|three|four).?)+/?$ ...
0
votes
2answers
440 views

need to redirect to static url based off of string patter match in uri

I have siteminder protecting an Oracle ADF java faces app. It appears I am going to have to intercept an http reqeust for the logout link delivered by Oracle in order to kill the siteminder session. ...
0
votes
2answers
108 views

Optimal mod_rewrite regex. Does the way the matching patterns are arranged inside the regex matter?

I have the following: RewriteRule ([a-zA-Z0-9]{5})?/load_page/([0-9]+) Which arrangement would be optimal for the regex: RewriteRule ^/([a-zA-Z0-9]{5})?/load_page/([0-9]+) OR RewriteRule ...
0
votes
1answer
639 views

Is it possible to match more than one regular expression with a single <ProxyMatch> rule?

I have a production, testing, and development server for a site that I maintain. All three servers are running Apache 2.2.16 on Debian 6 GNU/Linux. I have set up a new version of our company site on ...
1
vote
3answers
605 views

How to use Apache Piped Logs to regex replace out unwanted data in logs in real time?

I have https_acces_log log files being generated by Apache that a certain web app is logging unwanted data into the file. I can't stop the app from logging the data, so I'd like to write a ...
0
votes
1answer
47 views

Help with simple mod_rewrite needed

My site uses mod_rewrite for most URL's within the site. eg. domain.com/contact.htm domain.com/product/details.htm I've had domain.com/contact.htm working for a long time and is quite simple, but ...
0
votes
1answer
613 views

How to match this URL with PERL REGEX in SQUID?

I am trying to match this URL but Its not working not matching at all ... ...
2
votes
2answers
752 views

nginx rewrite config

I'm pretty new to nginx and am trying to setup some pretty simple rewrite rules, but they don't seem to be working. Just for your info, this server { .. } has its server_name domain.com *.domain.com. ...
2
votes
2answers
382 views

apache question mark RewriteRule question

So i am trying to redirect from index.php?action=search&query=search text goes here to search?query=search text goes here i tried this so far but with no luck RewriteRule ^search/? ...
0
votes
1answer
335 views

Multiple protected locations with Nginx

I am trying to secure couple of locations using the basic HTTP authentication that comes with Nginx, but for some reason it won't work. I have: website.com/admin (This is accesible by user ADMIN) ...
0
votes
1answer
683 views

HAProxy reqirep setting results in 504 Gateway Timeout

I am trying to rewrite a single path via HAProxy. Without the rule in place, a 404 is returned for the directory page (from an IIS node). Once I add the rule, the page returns a 504 Gateway Timeout ...
1
vote
2answers
999 views

Simple URI redirection / alias in Nginx

Please, how can I make this simple operation in Nginx: I wish that every requests for uris like: http://example.com/adm or: http://example.com/adm Goes to the wordpress login page: ...
1
vote
1answer
171 views

htaccess for wildcard subdomains

How to translate the example URL to the needed one? From http://test.at.domain.com To http://domain.com/at/index.php?at=test I have: RewriteEngine on RewriteCond %{HTTP_HOST} ...
4
votes
4answers
4k views

Copy multiple folders to a single destination with robocopy

I'm looking for a solution to use robocopy to copy several folders from a directory onto a distant network share. I want to choose several folders out of a directory that contains hundreds of folders ...