0

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?

Chase W.
  • 1,343
  • 2
  • 13
  • 25

3 Answers3

2

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

matt
  • 2,312
  • 5
  • 34
  • 57
0

What should I do?

Use a rewrite rule using mod_rewrite and .htaccess. Your rules might look like:

(example from Wordpress):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f    # Existing File
RewriteCond %{REQUEST_FILENAME} !-d    # Existing Directory
RewriteRule . /index.php [L]

More examples here and some more "simple" explanation here.

RobIII
  • 8,488
  • 2
  • 43
  • 93
0

Try create a file named .htaccess in your webroot with this content:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Also make sure that modrewrite is enabled.

tacone
  • 11,371
  • 8
  • 43
  • 60