.htaccess - htaccess rewrite subdirectory name to querystring param -


i have specific needs directory of website. need change

/thisdirectory/subdirectory 

to come through as

/thisdirectory?param=subdirectory 

i'm having issues creating htaccess file that. i've tried several different things, think closest:

rewriteengine on rewriterule ^/directory/(.*)\??(.*)$ /directory/?page=$1&$2 

i've been facing kinds of 500 server errors, infinite redirect loops, etc etc. appreciated, thanks!

i’m surprised work @ in per-directory context have strip per-directory path prefix pattern:

when using rewrite engine in .htaccess files per-directory prefix (which same specific directory) automatically removed rewriterule pattern matching , automatically added after relative (not starting slash or protocol name) substitution encounters end of rule set.

in case of document root directory leading / , rule this:

rewriterule ^directory/(.*)\??(.*)$ /directory/?page=$1&$2 

but besides that, rewriterule can check uri path , not query; need rewritecond that. try this:

rewriterule ^directory/(.+)$ /directory/?page=$1 [qsa] 

here .+ instead of .* should avoid infinite recursion .* matches everything, empty string (that case empty path segment after /directory/). , qsa flag automatically append requested uri query new one.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -