php - Conflicting Modrewrite Rules -


as previous questions may show you, not great modrewrite. have tried search , come empty particular issue. hope can assist me fixing up;

i using modrewrite part of short url generator, accessing unique id directly forward them destination. adding /v on end allow portal page display url being forwarded (like preview page)

because /v comes after id, works fine, want allow new pages added via $_get

this shortcut link being given users;

javascript:void(location.href='http://www.website.com/n/?url='+location.href) 

this content of .htaccess

rewriteengine on  rewriterule ^n actions.php?do=new [ns,l,nc] rewriterule ^([a-za-z0-9]+)$ actions.php?id=$1 [nc] rewriterule ^([a-za-z0-9]+)/([a-za-z0-9]+)$  actions.php?id=$1&do=$2 [nc] 

the problem: because /n in place of id, conflicts. have tried ns , l because able stop execution after rule matched. upon further inspection, of course dont work like.

finally, here examples of how url's desired in final product;

   new submission: http://www.web.com/n/?url=http://www.google.com      [outputs new url 12345]    visit id directly: http://www.web.com/1a2b34d5                       [forwards url destination]    visit id preview link: http://www.web.com/1a2b34d5/v             [displays preview, delayed forwarder] 

if want url variable query string add qsa options , save url in $_get['url']

rewriteengine on  rewritecond %{request_filename} !-f   # if url file not exist rewriterule ^n/?$ actions.php?do=new [ns,l,nc,qsa] rewriterule ^([a-za-z0-9]+)$ actions.php?id=$1 [nc,l] rewriterule ^([a-za-z0-9]+)/([a-za-z0-9]+)$  actions.php?id=$1&do=$2 [nc,l] 

also in actions.php have put conditions:

if (isset($_get['do'])) {     if ($_get['do'] == 'new') // http://www.web.com/n/?url=http://www.google.com     {         if (!isset($_get['url'])) die('no url');          // save url         // , outputs new url     }     else if ($_get['do'] == 'v') // http://www.web.com/1a2b34d5/v     {         // visit id preview link     } } else // http://www.web.com/1a2b34d5 {     // visit id directly } 

edit:

i don't know it's going on said in comment i've tested in localhost , works expected, in tests have test.php content var_dump($_get); i've created actions.php file same content , here url examples i've tested:

example1:

http://localhost/n?url=google.com or http://localhost/n/?url=google.com

this rule executed:

rewriterule ^n/?$ actions.php?do=new [ns,l,nc,qsa]

output:

array(2) { ["do"]=> string(3) "new" ["url"]=> string(10) "google.com" }

example2:

http://localhost/n12345 output: array(1) { ["id"]=> string(6) "n12345" } http://localhost/nnnn456 output: array(1) { ["id"]=> string(6) "nnnn456" }

this rule executed:

rewriterule ^([a-za-z0-9]+)$ actions.php?id=$1 [nc,l]

example3:

http://localhost/n12345/v output: array(2) { ["id"]=> string(6) "n12345" ["do"]=> string(1) "v" }

this rule executed:

rewriterule ^([a-za-z0-9]+)/([a-za-z0-9]+)$ actions.php?id=$1&do=$2 [nc,l]


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -