php - Clean url for static and dynamic pages -


i have website mixture of static pages without variables (ex: about.php) , dynamic pages (ex: searchresults.php?a=1&b=2)

right .htaccess allows static pages show, not dynamic ones. i've tried make dynamic pages work, however, breaks clean urls static pages.

rewriteengine on  directoryindex index.php index.html  rewritecond %{request_filename} !-f rewriterule ^([^\.]+)$ $1.php [nc,l] rewriterule ^([^\.]+)$ $1.html [nc,l] 

i final result this:

http://example.com/about.php -> http://example.com/about 

and

http://example.com/searchresults.php?a=1&b=2 -> http://example.com/searchresults/1/2 

is i'm looking possible?

yes, it's possible.

firstly, you'll need change rule strip extension. currently, have 2 rules match (meaning second never trigger), , second rule doesn't have condition.

secondly, search rule need specified explicitly.

your .htaccess file should this:

rewriteengine on  # rewrite search page  rewriterule ^searchresults/([^/]+)/([^/]+)/?$ searchresults.php?a=$1&b=$2 [qsa,l]  # allow requests without php/html extensions  rewritecond %{request_filename}.php -f rewriterule ^([^\.]+)$ $1.php [l]  rewritecond %{request_filename}.html -f rewriterule ^([^\.]+)$ $1.html [l] 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -