Hi I have written some rewrites, but from what I can tell from the logs it seems that the rules keep executing and so, although the correct result is achieved mid-execution, the final rewrite is incorrect.
Ideally I'd need to use the [END]
flag but I can't upgrade the server software which is Apache 2.2, so I'm going to have to work around that.
I'm trying to rewrite "/wedding?url=emily-and-john-2013" to "/wedding/emily-and-john-2013".
As I'm using CodeIgniter I first need to rewrite "index.php/wedding/..." to "/wedding/...".
Here are the rules I have so far.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
#Sends requests for /wedding/{blahblahblah} to
#/wedding?url={blahblahblah}
RewriteRule ^index.php/wedding/([^_]*)$ index.php/wedding?url=$1 [L]
</IfModule>
Here are the logs (slightly sanitised but you get the idea):
[*/sid#b8f1e8f0][rid#b93e1c68/initial] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/wedding -> SRV_PATH/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b93e1c68/initial] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/wedding/emily-and-john-2013 -> wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b93e1c68/initial] (3) [perdir SRV_PATH/] applying pattern '^(.*)$' to uri 'wedding/emily-and-john-2013'
[*/sid#b8f1e8f0][rid#b93e1c68/initial] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/wedding' pattern='!-f' => matched
[*/sid#b8f1e8f0][rid#b93e1c68/initial] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/wedding' pattern='!-d' => matched
[*/sid#b8f1e8f0][rid#b93e1c68/initial] (2) [perdir SRV_PATH/] rewrite 'wedding/emily-and-john-2013' -> 'index.php/wedding/emily-and-john-2013'
[*/sid#b8f1e8f0][rid#b93e1c68/initial] (3) [perdir SRV_PATH/] add per-dir prefix: index.php/wedding/emily-and-john-2013 -> SRV_PATH/index.php/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b93e1c68/initial] (2) [perdir SRV_PATH/] trying to replace prefix SRV_PATH/ with /
[*/sid#b8f1e8f0][rid#b93e1c68/initial] (5) strip matching prefix: SRV_PATH/index.php/wedding/emily-and-john-2013 -> index.php/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b93e1c68/initial] (4) add subst prefix: index.php/wedding/emily-and-john-2013 -> /index.php/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b93e1c68/initial] (1) [perdir SRV_PATH/] internal redirect with /index.php/wedding/emily-and-john-2013 [INTERNAL REDIRECT]
[*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding/emily-and-john-2013 -> index.php/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) [perdir SRV_PATH/] applying pattern '^(.*)$' to uri 'index.php/wedding/emily-and-john-2013'
[*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/index.php' pattern='!-f' => not-matched
[*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding/emily-and-john-2013 -> index.php/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) [perdir SRV_PATH/] applying pattern '^index.php/wedding/([^_]*)$' to uri 'index.php/wedding/emily-and-john-2013'
[*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (2) [perdir SRV_PATH/] rewrite 'index.php/wedding/emily-and-john-2013' -> 'index.php/wedding?url=emily-and-john-2013'
[*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) split uri=index.php/wedding?url=emily-and-john-2013 -> uri=index.php/wedding, args=url=emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) [perdir SRV_PATH/] add per-dir prefix: index.php/wedding -> SRV_PATH/index.php/wedding
[*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (2) [perdir SRV_PATH/] trying to replace prefix SRV_PATH/ with /
[*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (5) strip matching prefix: SRV_PATH/index.php/wedding -> index.php/wedding
[*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (4) add subst prefix: index.php/wedding -> /index.php/wedding
[*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (1) [perdir SRV_PATH/] internal redirect with /index.php/wedding [INTERNAL REDIRECT]
[*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding
[*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding -> index.php/wedding
[*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (3) [perdir SRV_PATH/] applying pattern '^(.*)$' to uri 'index.php/wedding'
[*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/index.php' pattern='!-f' => not-matched
[*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding
[*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding -> index.php/wedding
[*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (3) [perdir SRV_PATH/] applying pattern '^index.php/wedding/([^_]*)$' to uri 'index.php/wedding'
[*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (1) [perdir SRV_PATH/] pass through SRV_PATH/index.php
[*/sid#b8f1e8f0][rid#b93a1c80/subreq] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/wedding -> wedding
[*/sid#b8f1e8f0][rid#b93a1c80/subreq] (3) [perdir SRV_PATH/] applying pattern '^(.*)$' to uri 'wedding'
[*/sid#b8f1e8f0][rid#b93a1c80/subreq] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/wedding' pattern='!-f' => matched
[*/sid#b8f1e8f0][rid#b93a1c80/subreq] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/wedding' pattern='!-d' => matched
[*/sid#b8f1e8f0][rid#b93a1c80/subreq] (2) [perdir SRV_PATH/] rewrite 'wedding' -> 'index.php/wedding'
[*/sid#b8f1e8f0][rid#b93a1c80/subreq] (3) [perdir SRV_PATH/] add per-dir prefix: index.php/wedding -> SRV_PATH/index.php/wedding
[*/sid#b8f1e8f0][rid#b93a1c80/subreq] (2) [perdir SRV_PATH/] trying to replace prefix SRV_PATH/ with /
[*/sid#b8f1e8f0][rid#b93a1c80/subreq] (5) strip matching prefix: SRV_PATH/index.php/wedding -> index.php/wedding
[*/sid#b8f1e8f0][rid#b93a1c80/subreq] (4) add subst prefix: index.php/wedding -> /index.php/wedding
[*/sid#b8f1e8f0][rid#b93a1c80/subreq] (1) [perdir SRV_PATH/] internal redirect with /index.php/wedding [INTERNAL REDIRECT]
Note that on line 19 the correct URL is shown! Unfortunately it keeps running after that and some how the end result isn't correct.
Any ideas of how to change the rules to achieve the desired effect?
EDIT
I've just noticed that if I set the [R]
flag for a redirect rather than a rewrite then the browser ends up pointing at the correct URL. Not sure what bearing that has on anything.
EDIT 2
With the [NS]
flag added to the index.php
rule, here are the logs:
[*/sid#b8f1e8f0][rid#b9174dd0/initial] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/wedding -> SRV_PATH/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9174dd0/initial] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/wedding/emily-and-john-2013 -> wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9174dd0/initial] (3) [perdir SRV_PATH/] applying pattern '^(.*)$' to uri 'wedding/emily-and-john-2013'
[*/sid#b8f1e8f0][rid#b9174dd0/initial] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/wedding' pattern='!-f' => matched
[*/sid#b8f1e8f0][rid#b9174dd0/initial] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/wedding' pattern='!-d' => matched
[*/sid#b8f1e8f0][rid#b9174dd0/initial] (2) [perdir SRV_PATH/] rewrite 'wedding/emily-and-john-2013' -> 'index.php/wedding/emily-and-john-2013'
[*/sid#b8f1e8f0][rid#b9174dd0/initial] (3) [perdir SRV_PATH/] add per-dir prefix: index.php/wedding/emily-and-john-2013 -> SRV_PATH/index.php/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9174dd0/initial] (2) [perdir SRV_PATH/] trying to replace prefix SRV_PATH/ with /
[*/sid#b8f1e8f0][rid#b9174dd0/initial] (5) strip matching prefix: SRV_PATH/index.php/wedding/emily-and-john-2013 -> index.php/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9174dd0/initial] (4) add subst prefix: index.php/wedding/emily-and-john-2013 -> /index.php/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9174dd0/initial] (1) [perdir SRV_PATH/] internal redirect with /index.php/wedding/emily-and-john-2013 [INTERNAL REDIRECT]
[*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding/emily-and-john-2013 -> index.php/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) [perdir SRV_PATH/] applying pattern '^(.*)$' to uri 'index.php/wedding/emily-and-john-2013'
[*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/index.php' pattern='!-f' => not-matched
[*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding/emily-and-john-2013 -> index.php/wedding/emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) [perdir SRV_PATH/] applying pattern '^index.php/wedding/([^_]*)$' to uri 'index.php/wedding/emily-and-john-2013'
[*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (2) [perdir SRV_PATH/] rewrite 'index.php/wedding/emily-and-john-2013' -> 'index.php/wedding?url=emily-and-john-2013'
[*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) split uri=index.php/wedding?url=emily-and-john-2013 -> uri=index.php/wedding, args=url=emily-and-john-2013
[*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) [perdir SRV_PATH/] add per-dir prefix: index.php/wedding -> SRV_PATH/index.php/wedding
[*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (2) [perdir SRV_PATH/] trying to replace prefix SRV_PATH/ with /
[*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (5) strip matching prefix: SRV_PATH/index.php/wedding -> index.php/wedding
[*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (4) add subst prefix: index.php/wedding -> /index.php/wedding
[*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (1) [perdir SRV_PATH/] internal redirect with /index.php/wedding [INTERNAL REDIRECT]
[*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding
[*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding -> index.php/wedding
[*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (3) [perdir SRV_PATH/] applying pattern '^(.*)$' to uri 'index.php/wedding'
[*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/index.php' pattern='!-f' => not-matched
[*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding
[*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding -> index.php/wedding
[*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (3) [perdir SRV_PATH/] applying pattern '^index.php/wedding/([^_]*)$' to uri 'index.php/wedding'
[*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (1) [perdir SRV_PATH/] pass through SRV_PATH/index.php
[*/sid#b8f1e8f0][rid#b912c738/subreq] (1) [perdir SRV_PATH/] pass through SRV_PATH/wedding