Mod_rewrite flat links

后端 未结 2 335
忘了有多久
忘了有多久 2021-01-27 05:36

I\'m trying to display my get variables as flat links. Want to change from this:

http://mydomain.com/index.php?page=shop&var1=hat&var2=10
相关标签:
2条回答
  • 2021-01-27 06:00

    So first remember mod_rewrite works like this :

    http://mydomain.com/index.php/shop/hat/10
    

    (what the client type) is rewritten to

    http://mydomain.com/index.php?page=shop&var1=hat&var2=10
    

    (what the client is served), but not necessarily displayed like the latter. (Unless you make it a redirect)

    So assuming your format is completly described here :

    RewriteRule ^index\.php/([^/]+)/([^/]+)/([0-9]+)$ /index.php?page=$1&var2=$2&var2=$3
    

    Should be good.

    EDIT:

    Oh BTW! I did not take the variable number of variable into account. That should not be processed by mod_rewrite I think. Maybe the best shot is to RewriteRule index.php/(.*) /index.php?call=$1 and then use your script to explode using / delimiter.

    You can only do it if you already know the number of variable only AFAIK.

    0 讨论(0)
  • 2021-01-27 06:15

    You could just direct all request directly to index.php (called bootstrapping), and let the script parse out the variables.

    This is how it's done with Zend Framework, you should take a look at it. ZF also has loads of other goodies you could utilize.

    This is my rewrite block from one of my vhosts with a ZF powered website.

        RewriteCond %{REQUEST_FILENAME} !-l
        RewriteCond %{REQUEST_FILENAME} !-s
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI}      !^/favicon.ico
        RewriteRule ^.*$ index.php [NC,L]
    
    0 讨论(0)
提交回复
热议问题