php - RewriteRule to new URL and internally rewrite to old one -
my goal redirect users these paths:
/foo/index.php /foo/
to
/index
and have /index
load original content /foo/index.php
.
is possible in .htaccess
?
so far i've tried:
rewriterule ^foo/(index\.php)?$ /index [r=301,qsa,l] rewriterule ^index$ /foo/index.php [qsa,l]
but gets infinite redirection loop. thought adding rewritecond
uri help, docs:
note: conditions beingness processed after pattern of rewriterule
has matched.
so apparently rewritecond
won't of much utilize in utilize case.
looking through rewrite flags docs, s
flag seems i'm looking for:
this flag forces rewriting engine skip next num rules in sequence, if current rule matches. utilize create pseudo if-then-else constructs: lastly rule of then-clause becomes skip=n, n number of rules in else-clause.
so i've tried:
rewriterule ^index$ /foo/index.php [qsa,l,s=1] rewriterule ^foo/(index\.php)?$ /index [r=301,qsa,l]
though, have l
flag, s
flag seems little redundant. nevertheless, logic seems right in view, though still in infinite redirection loop.
right i'm using workaround php. first, apache internally rewrites new url old 1 , in php check if $_server['request_uri']
matches new format in origin of script, otherwise ensue 301 redirect new url.
though, i'd know whether possible .htaccess
solely? or if can explain how/why i'm getting infinite loop rewrite rules above grateful.
the problem rules in .htaccess
file, , docs say, file reparsed after every rewite loop, letst might have been applicable .htaccess
in different directory. l
flags in vain.
i have looked around, , if cannot place rewrite rules in main apache config, can offer next kludge: because server-variables the_request
not updated between rewrite runs, 1 can conclude "browser visible url" there , prevent rewriting in case:
# external redirect /index (unless browser shows /index plus query params) rewritecond %{the_request} !^\w+\ /index(\?.*)?\ http/1..$ rewriterule ^foo/(index\.php)?$ /index [r=301,qsa,l] # internal redirect /index rewriterule ^index$ /foo/index.php [qsa,l]
i thought there variable remains unchanged, right cannot find it. maybe else ?
php apache .htaccess mod-rewrite url-rewriting
No comments:
Post a Comment