Questions tagged [rewritemap]

When using `mod_rewrite`, the `RewriteMap` directive defines a "Rewriting Map" which can be used inside rule substitution strings to insert or substitute fields with a key/value lookup.

The RewriteMap directive defines a Rewriting Map which can be used inside rule substitution strings by the mapping-functions to insert/substitute fields through a key lookup. The source of this lookup can be of various types.

The MapName is the name of the map and will be used to specify a mapping-function for the substitution strings of a rewriting rule via one of the following constructs:

${ MapName : LookupKey }
${ MapName : LookupKey | DefaultValue }

For example, you might define a RewriteMap and RewriteRule as follows:

RewriteMap examplemap txt:/path/to/file/map.txt
RewriteRule ^/ex/(.*) /ex/index.php?path=${examplemap:$1}

If the map file contains a line reading foo bar, then that rule would rewrite a request for /ex/foo to /ex/index.php?path=bar.

Documentation: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritemap

81 questions
2
votes
3 answers

Apache RewriteRule with RewriteMap

I've got a RewriteMap that looks like this: Guide 1 Mini-Guide 2 White Paper 3 and I'm including it into Apache via RewriteMap legacy txt:/var/www/site/var/rewrite_map.txt I want to create a RewriteRule that will allow only…
Glen Solsberry
  • 11,960
  • 15
  • 69
  • 94
2
votes
1 answer

Apache RewriteMap directive with White List of IPs and IP Ranges

I am trying to use the RewriteMap directive in Apache to "white list" (allow only) a mix of certain ranges of IPs and with specific IPs. What makes this tricky for me is that the whitelist will contain a mix of large ranges of IPs such as 131.132.*…
user2390562
2
votes
2 answers

Rewriting url parameters using rewritemap and mysql

I realize this question has been beaten to death by a lot of people asking it, but most of the answers appear to be for a very specific case that only suits their needs, and so far I have not found a suitable solution (at least, as far as i can…
Human-Compiler
  • 11,022
  • 1
  • 32
  • 59
1
vote
1 answer

Protecting images from direct access by checking current PHP session with mod_rewrite

I'm working on a solution to a problem where users could potentially access images (in this case PDF files) stored in a folder off the server root. Normally, my application validates users through PHP scripts and sessions. What isn't happening…
a coder
  • 7,530
  • 20
  • 84
  • 131
1
vote
2 answers

What is the correct way to set up apache RewriteMap to pull from a Database? (PHP/APACHE/MYSQL)

I am trying to set up clean URL's on my small web app. Right now the URL's look like: http://www.mysite.com/productinfo.php?product=19 I want them to be: http://www.mysite.com/productinfo.php?product=Shoes How would I write both the RewriteMap and…
A Stubbs
  • 11
  • 1
1
vote
2 answers

If rewrite map doesn't exist got to 404

I've created a rewrite map that's working well: .htaccess RewriteRule ^([^/\.]+)/?$ index.php?page=${mymap:$1} [L] mymap.txt home 1 about 2 contact 3 So www.myurl/home works fine, but www.myurl/nonexistant_page doesn't exist in mymap.txt so I get…
Pardoner
  • 1,011
  • 4
  • 16
  • 28
1
vote
0 answers

Apache RewriteMap not working to find url exist on external file

How to check url exist in some external file . Just checking given request URI is in the list of vanity urls. Vanity url's file present at /mnt/var/www/html/vanity_urls.txt RewriteCond ${vanityurls:%{REQUEST_URI}|NONE} ^(.+)$ RewriteCond…
Satish ch
  • 21
  • 2
1
vote
1 answer

Apache 2.4 RewriteMap never matches

I'm using an Apache RewriteMap to permanently redirect 60 or so urls. In one development environment, the below configuration works flawlessly while in another development environment it doesn't work at all. Most notably, the last RewriteCond never…
curiouser
  • 970
  • 2
  • 12
  • 22
1
vote
0 answers

IIS Rewrite Maps for subdomain mapping

I am trying to write a dynamic sub-domain redirection rule using Rewrite Maps feature in IIS, given that our DNS server routes *.myapp.com to the same load balancer and ultimately the same application. Here's my current working implementation…
kent-id
  • 717
  • 10
  • 25
1
vote
1 answer

RewriteMap not working to prevent hotlinking

I am trying to prevent hot linking of images and adding allowed hosts by RewriteMap in txt file dynamically, but unfortunately the condition is not working. Here is code of VirtualHost DocumentRoot D:\XAMPP\htdocs\test\base …
Mian Majid
  • 814
  • 2
  • 8
  • 22
1
vote
0 answers

How to use Apache for short URLs?

What is this about? I recently stumbled upon the question if Apache can be used for generic shortlink generation? Why whould I prefer Apache over 3rd party software like yourls? Of course, there are other options than Apache for that, but let's…
Hello Fishy
  • 729
  • 5
  • 16
1
vote
1 answer

RewriteMap in httpd.conf and RewriteRule in .htaccess conflicting

I am working on a site where I have many short URLs which is redirected to a bigger version of URL. The idea is that the short URLs are distributed offline and users generally remembers them and types in the browser address bar. As…
1
vote
1 answer

Get .NET RewriteMap to work for old URL with or without trailing slash

I'm using a RewriteMap in my web.config file to (301) redirect old URLs to new URLs. The rule is currently as follows:
Dan
  • 5,836
  • 22
  • 86
  • 140
1
vote
1 answer

How to check is uri exists in rewritemap else goto 404 page?

My requirement is check if url exists in the rewrite map file. If not exists, it should show the custom 404 page with status code 404. Originally this code served the purpose: RewriteMap plp-map …
Saravana Prakash
  • 1,321
  • 13
  • 25
1
vote
2 answers

Rewrite Map Rule to match any URL extension

I'm fairly new to rewrite maps, but we did get ours to work on a very basic level. After a website redesign, we set up an extensive rewrite map (thousands o rules) to point the old pages to the new ones. The trouble we're having is that we're having…
vbertini
  • 11
  • 3