Lazar Bulatovic
Lazar Bulatovic

Reputation: 169

Url rewrite [Long url to short]

I'm developing CMS and want to make template system. So I could have multiple themes, like Wordpress has. But I have problem with urls. My question is how to rewrite this url:

http://example.com/themes/mytheme/post.php?slug=some-post-title

to something like this:

http://example.com/post/some-post-title

So point is to cut that part of themes/mytheme

Upvotes: 0

Views: 241

Answers (1)

samgak
samgak

Reputation: 24417

Try this:

RewriteEngine on
RewriteCond %{QUERY_STRING} slug=(.*)
RewriteRule ^([^/]*)/([^/]*)/post.php post/%1? [NC]

Tested here.

The RewriteCond detects the query string and allows for a back-substitution with %1 in the RewriteRule.

^([^/]*)/([^/]*)/ matches the first two folders.

The ? at the end of the RewriteRule is an empty query string so that the GET variables won't be passed through.

[NC] means case insensitive comparisons.

Upvotes: 1

Related Questions