rewrite this

Discuss practical ways rearrange URLs using mod_rewrite.

rewrite this

Postby Thomas » Sat Apr 23, 2005 11:16 pm

Hi

I have this URL

http://www.domain.org/ressourcer/?kat=dir

This is what i want

http://www.domain.org/ressourcer/dir/

also i have this:

http://www.domain.org/ressourcer/?kat=dir?page=1

and want this

http://www.domain.org/ressourcer/dir/1/

How is is this done. Just spend 3 hours of trying.
Thomas
 

Postby HM » Sun Apr 24, 2005 4:31 am

Place this .htaccess in your 'ressourcer' directory.
I'm assuming you meant ?kat=dir&page=1 as that is the correct way.
I'm unsure whether you'll need to rewrite to the index.php/pl/cgi or whatever script you're using, i'd recommend it, so here i've used index.php.

Code: Select all
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /?([^/]+)(/([0-9]+)/?)? /index.php?kat=$1&page=$2


You will receive an empty page number if the /pagenumber/ subfolder isn't used and trailing /'s are optional (? after /'s). You could replace the RewriteCond with
Code: Select all
RewriteRule /?index.php - [L]

You could also replace the [^/] in the first parenthesis with [a-z0-9] if your categories are only alphanumeric (then you'll probably want the [NC] flag).

There are lots of ways of doing it, all depends on exactly what you want.
HM
 


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 57 guests

cron