url rewriting index.php

前端 未结 2 994
挽巷
挽巷 2021-01-07 12:53

i have urls like

http://mysite.com/index.php?p=resources
http://mysite.com/index.php?p=resources&s=view&id=938

but i want urls like

2条回答
  •  花落未央
    2021-01-07 13:13

    I happen to use this in .htaccess:

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

    This essentially calls index.php no matter what is requested. Then inside your PHP code you can look at $_SERVER['REQUEST_URI'] to get the URL and parse it accordingly.

    The RewriteCond lines are there to exclude direct calls to files. In my case I don't want stuff like requests for js/css/image files to go through index.php for performance reasons.

提交回复
热议问题