php - HTACCESS causing 500 Internal Server Error -


note: code not being sanitized here simple explanation of problem, keeping basics. production code sanitize $_get before handling.

here .htaccess file:

rewriteengine on rewritecond %{request_uri} "/files/"  rewriterule (.*) $1 [l] rewriterule ^(.*)/(.*)$ ?cat=$1&title=$2 [l] rewriterule ^(.*) ?cat=$1 

here php file:

$cat = $_get['cat']; $title = $_get['title'];  if($cat && !$title) {     echo 1; }   if($cat && $title) {     echo 2; } 

if go test url of: http://local.testzone.com/cat/title or http://local.testzone.com/cat

i 500 internal server error.

if comment last line in .htaccess file:

#rewriterule ^(.*) ?cat=$1 

http://local.testzone.com/cat gives me:

not found

the requested url /cat not found on server.

http://local.testzone.com/cat/title gives me:

2

which should do, according my php echo of 2 if cat , title exist.

my question - how modify access file if there cat, echo 1? way manually set first level this:

rewriterule ^cat$ ?cat=cat 

this works, not work in application writing. need query database based on cat value in url. cat value can dynamically change , cannot hard code htaccess file. title working fine how cat portion function?

hope clear in request, looking forward assistance!

you can clean of rules, need add condition keep rules looping. rewrite enging continually run request uri through rules until uri stops changing (or reach internal recursion limit, 500 error).

rewriteengine on  rewriterule ^/?files/ - [l]  rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.*)/(.*)$ ?cat=$1&title=$2 [l]  rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.*) ?cat=$1 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -