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
16
votes
2 answers

Rewrite maps in IIS7 — how to make the match optionally include a trailing slash?

I have read the top 30 Google hits for several combinations of IIS rewrite map condition and so on, but I can't find any decent documentation, either on a microsoft.com site or elsewhere. I have a bunch of rewrite maps in IIS7 that I would like to…
Owen Blacker
  • 4,117
  • 2
  • 33
  • 70
11
votes
1 answer

IIS7 Rewrite Map Regex?

Is it possible to use reg ex in a rewrite map? For example: Or is there a way to handle this approach? Currently, I have a rule set up to match on…
Sam Gooch
  • 131
  • 1
  • 4
9
votes
4 answers

How can I match www AND non-www in a rewritecond?

I have a rewritemap that has a list of domains to redirect. Currently I have to list www.foo.com and foo.com in the rewrite map. I was wondering if there was a way to have the rewritecond check for both www and non-www in the same line. # Rewrite…
Scott Foster
  • 465
  • 3
  • 9
  • 17
6
votes
2 answers

Apache mod_rewrite: RewriteMap directive using PHP script on Windows machine

This has been driving me insane. I can't seem to get the RewriteMap directive to work for a php script on windows. Here is the relevant snippet from my httpd.conf file: RewriteEngine on RewriteMap router…
Skags
  • 139
  • 2
  • 5
5
votes
1 answer

Apache RewriteMap Used to Prevent Direct Access to Files

I am trying to use the result of a RewriteMap function to conditionally allow access to a directory. The intention is to read a timestamp from a cookie (my_cookie) and pass it into the RewriteMap (my_rewrite_map_func) which I have defined in…
lizbit
  • 313
  • 1
  • 12
5
votes
1 answer

Error 500 when I have RewriteMap in .htaccess

I have a map file in this format 233 Alabama/Phenix-City/Ridgebrook 237 Alabama/Ft.-Mitchell/Riverside-Estates I have the following .htaccess script. I'm getting a 500 Internal Server Error when the page in question is hit. RewriteEngine…
Vibration Of Life
  • 3,177
  • 3
  • 22
  • 23
5
votes
2 answers

use RewriteMap in htaccess file

How can i use RewriteMap directive in htaccess file? When i put it there i get "RewriteMap not allowed here" error. I know this error will disappear when put it in httpd.conf or virtualhost configuration file. But i want to know is it possible to…
hd.
  • 17,596
  • 46
  • 115
  • 165
4
votes
1 answer

RewriteMap not working in mod-rewrite

I have been trying to do simple maping with RewriteMap directive in my htaccess, but for some reason i am getting error 500 everytime. my syntax is .. Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteMap name2id…
Wasim
  • 67
  • 1
  • 5
3
votes
1 answer

Apache RewriteMap syntax for full URLs

I have a rewrite map with around 5000 entries like this: http://www.example.com/some-random-url http://www.example.net/some-random-url For each entry the source domain, eg example.com above, is the same, but the destination domain, example.net…
3
votes
1 answer

Using variable in RewriteCond condition patern

I want to associate user Ids to a specific application Id like: 615 1 616 7 617 3 618 3 My URIs looks like: ///... Now, I want to be able to easily change the application without impacting the user…
Asterius
  • 2,180
  • 2
  • 19
  • 27
3
votes
4 answers

mod_rewrite send everything not matched to a rewritemap

I have an htaccess file which begins with the regular stuff: RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d then has a few rewrites eg: RewriteRule ^protect/?$…
Adam Hopkinson
  • 28,281
  • 7
  • 65
  • 99
3
votes
1 answer

NGINX / Apache RewriteMap

I would like to know how to translate Apache "RewriteMap" directives in NGINX. I've found nothing in the NGINX online documentation My current apache code is: RewriteMap map-one txt:C:/map-one.txt RewriteMap map-two txt:C:/map-two.txt
Caleb2000
  • 31
  • 1
  • 3
2
votes
1 answer

Apache RewriteMap with wildcard condition

I am using apache RewriteMap with a text file to map some old urls to new urls, in my file (red.map) I have /old-awful-url.html /new-lovely-shiny-url.html Then in my apache config I have:- RewriteEngine On RewriteMap migration …
Andrew Smith
  • 117
  • 9
2
votes
1 answer

IIS Url Rewrite Maps & Wildcard URLs

Using IIS Url Rewrite, is it possible to match wildcard URLs using RewriteMaps? For example, I have the following rewrite rule:
Dan Lister
  • 2,543
  • 1
  • 21
  • 36
2
votes
1 answer

IIS RewriteMap Rule causes 500 error

I am totally new to IIS servers and need to implement some rewrites. The following rule in my RewriteMaps file causes a 500 error: While this…
Dbrandt
  • 37
  • 4
1
2 3 4 5 6