url rewriting index.php

前端 未结 2 992
挽巷
挽巷 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.

    0 讨论(0)
  • 2021-01-07 13:26

    Create a .htaccess file. Not somefilename.htaccess, it is simply named .htaccess.
    Note: Your index.php and .htaccess file should be in the same directory.

    Now try this on your .htaccess file

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^([A-Za-z0-9\-]+)$ index.php?p=resources
    RewriteRule ^([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/([0-9]+)$ index.php?p=resources&s=view&id=938
    </IfModule>

    see more about url rewrite here

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