Reputation: 6252
I'm currently redirecting all requests to the index.php file using the following:
<IfModule mod_rewrite.c>
RewriteEngine on
# base path, if not the root directory
RewriteBase /dev/public/
# direct all requests to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php
</IfModule>
While this works, it limits my code to only being able to run on servers with mod_rewrite enabled. So I'm wondering, is there a way to simulate this behavior without using .htaccess? How do other frameworks do it?
Upvotes: 5
Views: 2074
Reputation:
Hosts like Yahoo don't allow .htaccess, which can be a little frustrating. Redirecting like that isn't possible as far as I know, but this is a workaround:
have this file structure:
index.php
private/ <-- you could do: password protect, set permissions, name with hard to guess string, etc
public/
So accessing example.com/page
will output 404, but you can redo your urls to example.com/index.php/page
This is what I use to get the URI args in an array:
$uri_args =
explode('/', substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], 'index.php') + 10));
Optionally, to delete the empty args:
array_filter($uri_args);
See my question: How To Rewrite URL in PHP Only?
(See also http://php.net/manual/en/reserved.variables.server.php and Remove empty array elements)
Upvotes: 1
Reputation: 446
if you dont want to user htaccess you can make your all link like index.php?c=products&m=view&id=345
so your all request is going to the index.php any way and you dont need htaccess
Upvotes: 1
Reputation: 8662
you can write a short php script:
<?php
header( 'Location: index.php' ) ;
?>
and include it on the top of all your php files except index.php
Upvotes: 1