Redirect everything to index.php

前端 未结 3 680
挽巷
挽巷 2020-12-10 17:45

I\'m trying to do clean URLs by exploding $_SERVER[\'REQUEST_URI\'] and then switching between the results.

However, once a user goes outside inde

相关标签:
3条回答
  • 2020-12-10 18:22

    You will need images, and other files what will show up in the index.php.

    RewriteEngine On
    

    Turns on the Rewite Engine

    RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$
    

    If the filename is not equal JPG, JPEG... which need for index.php

    RewriteRule ^(.*)$ index.php?q=$1 [QSA]
    

    "Redirect" to index.php.

    In use:

    With PHP $_GET the q will give you the /articles/1987/12/20/Répa's birthday/

    If you split the variable in every slash with

    list($type, $date_year, $date_month, $date_day, $title) = split('[/-]', $_GET['q']);
    

    You will got exactly what you want.

    0 讨论(0)
  • 2020-12-10 18:38

    .htaccess:

    RewriteEngine on
    RewriteBase /
    RewriteCond  %{REQUEST_FILENAME} !-f
    RewriteCond  %{REQUEST_FILENAME} !-d
    RewriteRule  ^(.*)$ index.php?param=$1 [QSA,L]
    
    0 讨论(0)
  • 2020-12-10 18:41

    You can use Apache's mod_rewrite to map URLs based on regular expressions, including sending everything to index.php,

    0 讨论(0)
提交回复
热议问题