Reputation: 363
I'm creating a website for a client, who would like NOT to use Drupal, but would like a Drupal-style mod rewrite (friendly url) feature on their website.
Having never created my own mod_rewrite engine before, are there any handy hints or tips you can give me? The CMS is totally created by me, and it would be nice to offer this feature, so if you could help, thanks in advance.
Upvotes: 0
Views: 270
Reputation: 9808
Add that to your htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/?argv=$1 [L]
and index.php/?argv=mypage will becomes /mypage then furthermore a php snippet to get the URI into an array
if($_GET['argv']){
$argc = count($argv);
$myURI = explode('/',$_GET['argv']);
$controller = ($argc < 0) ?: $myURI[0];
$action = (argc > 1) ? $myURI[1] : 'index';
$params = (argc < 2) ?: array_slice($myURI, 2);
}
That's what I'm using on my mvc.
Upvotes: 1
Reputation: 16086
mod_rewrite Rewrite Rule generator will take a dynamic url given to it, and generate the correct syntax to place in a .htaccess file to allow the url to be rewritten in a spiderable format. The apache module "mod_rewrite" (which you need to enable) converts urls in a certain format to another format, and can be very useful in helping a site with dynamic content to be indexed.
Syntax: RewriteRule url-pattern url-new [[flag,...]]
Example: RewriteRule ^/foo/(.*)$ /bar/$1 [R,L]
Upvotes: 0