How do you do it all at the mod_rewrite?



  • I'm writing a website on PHP, using the Apache server. I need to redirect the address to www, man-made URL, redesign to the canonic URL, multi-lingualism, ban some laser agents, ban IP users, and a lot of things with mod_rewrite, all of which are built through hell.

    How do I do that?



  • You're going wrong. If you do anything through mod_rewrite, you'll face a lot of problems:

    • You'll be contaminated with tons of unreadable and unsupported code. This language is not intended for complex logic, even though it's a parole on Turing.

    • You'll kill your website with nails to the Apache server. If you want to use the nginx, you'll have serious problems.

    • It's almost impossible to maintain the rules. If you run into a bagom that doesn't fix a hard look at the code, it's gonna be hard to find a mistake.

    • If you have edited rules through the Admincture (humanitated URL, encumbered IP bands, etc.), editing software. .htaccess It'll be a problem.

    Today ' s Freamworths and CMS use rolling across the front controller. That's all you need:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?_route=$1 [L,QSA]
    

    Now index.php You will be on your way. $_GET['_route']all other parameters in the GET request will also be retained. You can write whatever logic you want in a language you know and understand, using any kind of means of access to the configuration to get the Rooting lines and access to the base to get the IP bands.

    If you're not embarrassed about accessing the way through. $_SERVER['REQUEST_URI'] instead $_GET['_route']♪ You can make it easier ♪ .htaccess More, as indicated in the notes to another reply:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L,QSA]
    

    P. S. Canon URL usually suffice in the meta-information of the page. Adjustments due to absence / at the end, they're just wasting their resources. Also available https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState so that the URL in the address line of the browser is canonal, too.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2