Forum Moderators: phranque
[edited by: phranque at 9:47 pm (utc) on May 21, 2013]
[edit reason] please use example.com to prevent linking example urls [/edit]
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule / stop-account.html [L]
RewriteRule ^.*$ ...
RewriteCond %{HTTP_HOST} example\.com$ RewriteRule ^index.html$ http://www.domain.com/stop-account.html [L] @Diveded, your understanding is correct.
RewriteRule / stop-account.html [L] RewriteCond %{REQUEST_URI} !/stop-account.html$ RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteEngine On
# Rewrite root requests to stop-account.html
# (Note that if there's a directory index in this path, such as index.html,
# then mod_dir will send that response before any of these rewrite rules get the chance to run.)
RewriteRule ^$ stop-account.html
# Redirect all other requests to stop-account.html
# (unless the request is for stop-account.html itself)
RewriteCond $1 !=stop-account.html
RewriteRule (.*) /stop-account.html [R,L]
If there has been an internal rewrite to stop-account.html, then it won't be reflected in the request URI.
RewriteCond %{REQUEST_URI} !^stop-account.html$
RewriteRule ^$ stop-account.html [L] You're confusing REQUEST_URI with THE_REQUEST. Although the names are similar, functionally they're very different. THE_REQUEST looks at what the User-Agent itself originally asked for. But REQUEST_URI means "whatever file you're currently looking at, whether it was an explicit request, the result of a rewrite, or even a subrequest".
RewriteRule / stop-account.html
RewriteCond %{REQUEST_URI} !/stop-account.html$
RewriteRule ^.*$ /stop-account.html [R=302,L] /foo/bar How do you get mod_dir to not run until after a rewrite?
RewriteEngine On
RewriteRule ^$ stop-account.html Request for directory
+ rule constrained to .html
=
rule WORKS if configured as an internal rewrite only [L]
rule DOES NOT work if configured as an external redirect [R=301,L]
RewriteRule ^index\.html$ stop-account.html Do you get something different?
g1, if you are back in the land of the living I wish you would have a look at this recent thread [webmasterworld.com]. While experimenting I discovered something I can't explain, no way, no how-- and the identical thing happens on two different Apache installations.
# Will mod_dir or mod_rewrite get to process this?
RewriteRule ^$ rewrite-intercepted-root.html [initial] strip per-dir prefix: C:/Apache24/htdocs/ ->
[initial] applying pattern '^$' to uri ''
[initial] rewrite '' -> 'rewrite-intercepted-root.html'
[initial] add per-dir prefix: rewrite-intercepted-root.html -> C:/Apache24/htdocs/rewrite-intercepted-root.html
[initial] strip document_root prefix: C:/Apache24/htdocs/rewrite-intercepted-root.html -> /rewrite-intercepted-root.html
[initial] internal redirect with /rewrite-intercepted-root.html [INTERNAL REDIRECT]
[subreq] strip per-dir prefix: C:/Apache24/htdocs/index.html -> index.html
[subreq] applying pattern '^$' to uri 'index.html'
[subreq] pass through C:/Apache24/htdocs/index.html
Response sent with status 200, headers: RewriteRule ^$ /rewrite-intercepted-root.html [R,L] [initial] strip per-dir prefix: C:/Apache24/htdocs/ ->
[initial] applying pattern '^$' to uri ''
[initial] rewrite '' -> '/rewrite-intercepted-root.html'
[initial] explicitly forcing redirect with http://localhost/rewrite-intercepted-root.html
[initial] escaping http://localhost/rewrite-intercepted-root.html for redirect
[initial] redirect to http://localhost/rewrite-intercepted-root.html [REDIRECT/302]
Response sent with status 302, headers: RewriteRule ^(.*/)?index\.html$ /$1 [R,L] RewriteRule ^(.*/)?index\.html$ /$1 [R,L]
RewriteRule ^$ rewrite-intercepted-root.html [initial] strip per-dir prefix: C:/Apache24/htdocs/index.html -> index.html
[initial] applying pattern '^(.*/)?index\\.html$' to uri 'index.html'
[initial] rewrite 'index.html' -> '/'
[initial] explicitly forcing redirect with http://localhost/
[initial] escaping http://localhost/ for redirect
[initial] redirect to http://localhost/ [REDIRECT/302]
Response sent with status 302, headers:
----
[initial] strip per-dir prefix: C:/Apache24/htdocs/ ->
[initial] applying pattern '^(.*/)?index\\.html$' to uri ''
[initial] strip per-dir prefix: C:/Apache24/htdocs/ ->
[initial] applying pattern '^$' to uri ''
[initial] rewrite '' -> 'rewrite-intercepted-root.html'
[initial] add per-dir prefix: rewrite-intercepted-root.html -> C:/Apache24/htdocs/rewrite-intercepted-root.html
[initial] strip document_root prefix: C:/Apache24/htdocs/rewrite-intercepted-root.html -> /rewrite-intercepted-root.html
[initial] internal redirect with /rewrite-intercepted-root.html [INTERNAL REDIRECT]
[subreq] strip per-dir prefix: C:/Apache24/htdocs/index.html -> index.html
[subreq] applying pattern '^$' to uri 'index.html'
[subreq] pass through C:/Apache24/htdocs/index.html
Response sent with status 200, headers: RewriteRule ^(.*/)?index\.html$ /$1 [R,L]
RewriteRule ^$ rewrite-intercepted-root.html
RewriteRule ^mod_dir-will-apply-this$ /
RewriteRule ^mod_dir-will-not-apply-this$ / [R] strip per-dir prefix: C:/Apache24/htdocs/index.html -> index.html
applying pattern '^$' to uri 'index.html'
strip per-dir prefix: C:/Apache24/htdocs/index.html -> index.html
applying pattern '^mod_dir-will-apply-this$' to uri 'index.html'
pass through C:/Apache24/htdocs/index.html [edited by: phranque at 8:12 am (utc) on Jun 2, 2013]
[edit reason] clean up system tracks [/edit]
mod_dir will run after mod_rewrite, but it will ignore the result of the rewrite
request for /hoosegow/ yields content of /dunnykin/index.html (which can only happen via mod_dir)
# Things start off simple and straightforward.
# A request for "/hoosegow/" is rewritten to "/dunnykin/".
[initial] strip per-dir prefix: C:/Apache24/htdocs/hoosegow/ -> hoosegow/
[initial] applying pattern 'hoosegow' to uri 'hoosegow/'
[initial] rewrite 'hoosegow/' -> '/dunnykin/'
[initial] internal redirect with /dunnykin/ [INTERNAL REDIRECT]
# Next, mod_dir issues a subrequest.
# But it isn't looking for "dunnykin/index.html",
# it's looking for "hoosegow/index.html",
# as if the previous rewrite didn't happen.
# The rewrite rule is re-applied to this subrequest,
# and "hoosegow/index.html" is rewritten to "/dunnykin/".
[subreq] strip per-dir prefix: C:/Apache24/htdocs/hoosegow/index.html -> hoosegow/index.html
[subreq] applying pattern 'hoosegow' to uri 'hoosegow/index.html'
[subreq] rewrite 'hoosegow/index.html' -> '/dunnykin/'
[subreq] internal redirect with /dunnykin/ [INTERNAL REDIRECT]
# An internal redirect finally took place, evidenced by "initial/redir#1".
# The rewrite rules are applied again, but this time the request is for "/dunnykin/",
# so the rewrite patterns don't match.
[initial/redir#1] strip per-dir prefix: C:/Apache24/htdocs/dunnykin/ -> dunnykin/
[initial/redir#1] applying pattern 'hoosegow' to uri 'dunnykin/'
[initial/redir#1] pass through C:/Apache24/htdocs/dunnykin/
# mod_dir issues another subrequest, finally this time for "dunnykin/index.html".
[subreq] strip per-dir prefix: C:/Apache24/htdocs/dunnykin/index.html -> dunnykin/index.html
[subreq] applying pattern 'hoosegow' to uri 'dunnykin/index.html'
[subreq] pass through C:/Apache24/htdocs/dunnykin/index.html
Response sent with status 200, headers:
Every time you post a RewriteRule without an [L] flag (unless it is one with an [F] or [G] flag where the [L] is implied), a kitten dies.
Every time you post a RewriteRule without an [L] flag (unless it is one with an [F] or [G] flag where the [L] is implied), a kitten dies.