dongling4383 2014-02-19 23:13 采纳率: 100%
浏览 674
已采纳

通过带有斜杠的url传递参数

I am trying to pass variables through the url without including ?var1=test but have that replaced with /test. I have the following code:

$pathinfo = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : $_SERVER['REDIRECT_URL'];    
$params = preg_split('|/|', $pathinfo, -1, PREG_SPLIT_NO_EMPTY);
print_r($params);

This issue is, if I put this in the index.php file, I have to include the filename.

What I get: http://example.com/index.php/test

What I want: http://example.com/test

What should I do?

  • 写回答

3条回答 默认 最新

  • ds08541 2014-02-19 23:17
    关注

    Add a .htaccess file in your root folder and paste this code

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    

    Just make sure mod_rewrite is enabled

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?