.htaccess Regex Match File with Extensions or no Extension -
basically want match of patterns below file path after protocol through file name, file doesn't have extension.
i got there, once try make match files without extension, matches until rest of line.
my test strings
http://regexr.com/foo.html?test (//regexr.com/foo.html) http://regexr.com/foo?test (//regexr.com/foo) http://regexr.com/foo.php?test (//regexr.com/foo.htm) http://regexr.com/foo.htm?test (//regexr.com/foo.htm)
my current expression \/(.+)\.php
doesn't match second file path without extension, , if make last collection optional, selects through parameters. appreciated.
edit below .htaccess block i'm attempting modify
rewritecond %{request_filename} !-d rewritecond %{the_request} \ /(.+)(\.php|\.html?) rewriterule ^ /%1.aspx [l,r=301] rewriterule ^(.*).aspx$ $1.php [qsa]
further edit pointed out, may have been better asked redirect question. (another note, removed html redirect since causes performance hit, files extension *.php
files being redirected.)
these how have files handled; 301 redirecting new address , continuing processed php server such:
http://regexr.com/foo.html (doesn't redirect, not processed) http://regexr.com/foo (r /foo.aspx, processed /foo.php) http://regexr.com/foo.php (r /foo.aspx, processed /foo.php) http://regexr.com/foo.htm (doesn't redirect, not processed) http://regexr.com/foo.aspx (doesn't redirect, processed /foo.php)
you can use regex pattern:
\s/([^?.]+)(?:\.php|\.html?)?[?\s]
redirect rule:
rewriteengine on rewritecond %{request_filename} !-d rewritecond %{the_request} \s/([^?.]+)(?:\.php)?[?\s] [nc] rewriterule ^ /%1.aspx? [l,r=302] rewriterule ^(.+?)\.aspx$ $1.php [l,nc]
Comments
Post a Comment