Mahbub
Mahbub

Reputation: 195

mod_rewrite RewriteCond and query string

recently, I have been working on a small project for a client. I was thinking about using a wordpress style pretty URL format. I googled around a lot and came accross Apache’s mod_rewrite and RewriteRule, RewriteCond. But didn't find any example which can handle random of parameters. For example:

or something similar.

As you can see parameters are not fixed. Is there anyway to achieve this? Any help would be greatly appreciate.

Thanks

Upvotes: 0

Views: 778

Answers (1)

gblazex
gblazex

Reputation: 50109

Most CMS does this with PHP.

.htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

PHP

$URI = substr($_SERVER['REQUEST_URI'], 1);
$URIparts = explode("/", $URI);

Then you've got an array of the parts of the url, and you can process them as you want.

Upvotes: 1

Related Questions