470,849 Members | 1,149 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Htaccess question w/ mod rewrite

Hi group,

I know this isn't the right group, but i didn't know what group else it
should be.
I have a php/mySQL system, wich uses mod rewrite to enhance urls.

I have the following RewriteRule:

RewriteRule
^news(/[0-9]{4}(/[0-9]{2}(/[A-z0-9_-]+)?)?)?)?(/(index\.html)?)?$
index.php

Allows urls as:

domain.com / news / 2006 / 02 / some_news-itemName / index.html

structure:

domain / news / year / month / news item's name

A trailing slash, and optionally 'index.html' are alwas allowed this
way, an item name can only be given if a month is defined, which can
only be defined if a year is defined.

Now how can i divide the different information parts into $_GET in the
url, like

index.php?year=2006&month=02&topic=some_news-itemName

$1 gives me: /2006/02/some_news-itemName
$2 gives me: /02/some_news-itemName
$3 gives me: /some_news-itemName
$4 gives me: /index.html
$5 gives me: index.html

So i'd like the $_GET's to be more 'precise'.

Hope it's clear!

Frizzle.

Feb 9 '06 #1
5 1228
d
"frizzle" <ph********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi group,

I know this isn't the right group, but i didn't know what group else it
should be.
I have a php/mySQL system, wich uses mod rewrite to enhance urls.

I have the following RewriteRule:

RewriteRule
^news(/[0-9]{4}(/[0-9]{2}(/[A-z0-9_-]+)?)?)?)?(/(index\.html)?)?$
index.php

Allows urls as:

domain.com / news / 2006 / 02 / some_news-itemName / index.html

structure:

domain / news / year / month / news item's name

A trailing slash, and optionally 'index.html' are alwas allowed this
way, an item name can only be given if a month is defined, which can
only be defined if a year is defined.

Now how can i divide the different information parts into $_GET in the
url, like

index.php?year=2006&month=02&topic=some_news-itemName

$1 gives me: /2006/02/some_news-itemName
$2 gives me: /02/some_news-itemName
$3 gives me: /some_news-itemName
$4 gives me: /index.html
$5 gives me: index.html

So i'd like the $_GET's to be more 'precise'.

Hope it's clear!

Frizzle.


A very easy way is to look at $_SERVER["REQUEST_URI"]. If you explode("/",
$_SERVER["REQUEST_URI"]), you get an array of the individual directories in
your request, each one corresponding to a variable. If you're worried about
portability, there is a free library for IIS that does the same as
mod_rewrite, and it even sets a similar header.

Hope that helps!

dave
Feb 9 '06 #2
frizzle wrote:
Hi group,

I know this isn't the right group, but i didn't know what group else it
should be.
I have a php/mySQL system, wich uses mod rewrite to enhance urls.

I have the following RewriteRule:

RewriteRule
^news(/[0-9]{4}(/[0-9]{2}(/[A-z0-9_-]+)?)?)?)?(/(index\.html)?)?$
index.php

Allows urls as:

domain.com / news / 2006 / 02 / some_news-itemName / index.html

structure:

domain / news / year / month / news item's name

A trailing slash, and optionally 'index.html' are alwas allowed this
way, an item name can only be given if a month is defined, which can
only be defined if a year is defined.

Now how can i divide the different information parts into $_GET in the
url, like

index.php?year=2006&month=02&topic=some_news-itemName

$1 gives me: /2006/02/some_news-itemName
$2 gives me: /02/some_news-itemName
$3 gives me: /some_news-itemName
$4 gives me: /index.html
$5 gives me: index.html

So i'd like the $_GET's to be more 'precise'.


Try something like this (notice where the groups are and the ? operator):

RewriteRule ^news(/[0-9]{4})?(/([0-9]{2}))?(/([^/]+))?(/(index\.html))?$
index.php?year=$1&month=$3&topic=$5

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Feb 9 '06 #3

Justin Koivisto wrote:
frizzle wrote:
Hi group,

I know this isn't the right group, but i didn't know what group else it
should be.
I have a php/mySQL system, wich uses mod rewrite to enhance urls.

I have the following RewriteRule:

RewriteRule
^news(/[0-9]{4}(/[0-9]{2}(/[A-z0-9_-]+)?)?)?)?(/(index\.html)?)?$
index.php

Allows urls as:

domain.com / news / 2006 / 02 / some_news-itemName / index.html

structure:

domain / news / year / month / news item's name

A trailing slash, and optionally 'index.html' are alwas allowed this
way, an item name can only be given if a month is defined, which can
only be defined if a year is defined.

Now how can i divide the different information parts into $_GET in the
url, like

index.php?year=2006&month=02&topic=some_news-itemName

$1 gives me: /2006/02/some_news-itemName
$2 gives me: /02/some_news-itemName
$3 gives me: /some_news-itemName
$4 gives me: /index.html
$5 gives me: index.html

So i'd like the $_GET's to be more 'precise'.


Try something like this (notice where the groups are and the ? operator):

RewriteRule ^news(/[0-9]{4})?(/([0-9]{2}))?(/([^/]+))?(/(index\.html))?$
index.php?year=$1&month=$3&topic=$5

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com


Doesn't this allow me to define a month in the url, without defining a
year?

Frizzle.

Feb 9 '06 #4
frizzle wrote:
Justin Koivisto wrote:
frizzle wrote:
Hi group,

I know this isn't the right group, but i didn't know what group else it
should be.
I have a php/mySQL system, wich uses mod rewrite to enhance urls.

I have the following RewriteRule:

RewriteRule
^news(/[0-9]{4}(/[0-9]{2}(/[A-z0-9_-]+)?)?)?)?(/(index\.html)?)?$
index.php

Allows urls as:

domain.com / news / 2006 / 02 / some_news-itemName / index.html

structure:

domain / news / year / month / news item's name

A trailing slash, and optionally 'index.html' are alwas allowed this
way, an item name can only be given if a month is defined, which can
only be defined if a year is defined.

Now how can i divide the different information parts into $_GET in the
url, like

index.php?year=2006&month=02&topic=some_news-itemName

$1 gives me: /2006/02/some_news-itemName
$2 gives me: /02/some_news-itemName
$3 gives me: /some_news-itemName
$4 gives me: /index.html
$5 gives me: index.html

So i'd like the $_GET's to be more 'precise'.


Try something like this (notice where the groups are and the ? operator):

RewriteRule ^news(/[0-9]{4})?(/([0-9]{2}))?(/([^/]+))?(/(index\.html))?$
index.php?year=$1&month=$3&topic=$5

Doesn't this allow me to define a month in the url, without defining a
year?


Yes, that would, maybe something more like this then (untested):

RewriteRule ^news(/([0-9]{4})/([0-9]{2})/([^/]+))?(/(index\.html)?)?$
index.php?year=$2&month=$3&topic=$4
Feb 11 '06 #5

Justin Koivisto wrote:
frizzle wrote:
Justin Koivisto wrote:
frizzle wrote:

Hi group,

I know this isn't the right group, but i didn't know what group else it
should be.
I have a php/mySQL system, wich uses mod rewrite to enhance urls.

I have the following RewriteRule:

RewriteRule
^news(/[0-9]{4}(/[0-9]{2}(/[A-z0-9_-]+)?)?)?)?(/(index\.html)?)?$
index.php

Allows urls as:

domain.com / news / 2006 / 02 / some_news-itemName / index.html

structure:

domain / news / year / month / news item's name

A trailing slash, and optionally 'index.html' are alwas allowed this
way, an item name can only be given if a month is defined, which can
only be defined if a year is defined.

Now how can i divide the different information parts into $_GET in the
url, like

index.php?year=2006&month=02&topic=some_news-itemName

$1 gives me: /2006/02/some_news-itemName
$2 gives me: /02/some_news-itemName
$3 gives me: /some_news-itemName
$4 gives me: /index.html
$5 gives me: index.html

So i'd like the $_GET's to be more 'precise'.

Try something like this (notice where the groups are and the ? operator):

RewriteRule ^news(/[0-9]{4})?(/([0-9]{2}))?(/([^/]+))?(/(index\.html))?$
index.php?year=$1&month=$3&topic=$5

Doesn't this allow me to define a month in the url, without defining a
year?


Yes, that would, maybe something more like this then (untested):

RewriteRule ^news(/([0-9]{4})/([0-9]{2})/([^/]+))?(/(index\.html)?)?$
index.php?year=$2&month=$3&topic=$4


Not to be a nag, but this forces me to use all 3 parameters. So i
would'nt be able to
browse e.g. a month, or a year ...

Frizzle.

Feb 11 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Nel | last post: by
15 posts views Thread by Taki Jeden | last post: by
2 posts views Thread by Geradeaus | last post: by
unicorn
3 posts views Thread by unicorn | last post: by
9 posts views Thread by invertigo | last post: by
3 posts views Thread by Joe | last post: by
4 posts views Thread by adnanjunk | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.