dongshou6041 2014-12-03 01:00
浏览 53

如何进行目录重定向

I've seen websites have profile pages do things like 'http://www.example.com/myusername/ show the the person with the username 'myusername's' profile. I was wondering how to do this?

I've seen examples on how to do this with htaccess but it does a full redirect, not allowing post data, get data, etc. How could I do this?

  • 写回答

2条回答 默认 最新

  • douhanshu5517 2014-12-03 01:09
    关注

    Use .htaccess's mod_rewrite option to create rewrites that will maintain the query string and/or posted data. A quick example (taken from CodeIgniter) :

    RewriteEngine on
    RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    This will mean that all requests go to index.php and your index.php script would be setup to parse this URL into a proper class and/or function. This allows for a single entry point that can be managed by a system. This is used by all major systems, from Wordpress to Magento to Laravel 4 to CodeIgniter.

    评论

报告相同问题?