473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1307
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Nel | last post by:
Just looking for some general advice on modifying the URL for php. I am using .htaccess to allow a web site to translate example.html to index.php?content=example (below) ErrorDocument 404...
15
by: Taki Jeden | last post by:
Hello everybody Does anybody know why w3c validator can not get pages that use 404 htaccess redirection? I set up two web sites so that clients request non-existent urls, but htaccess redirects...
2
by: Geradeaus | last post by:
I use htaccess to rewrite the url using the following rules : RewriteRule ^(+)/(+)/(+)?$ index.php?lang=$1&page=$2&id=$3 The only problem I have is when http://www.domain.com/admin is given,...
5
by: tommytx | last post by:
Is there any capability of decisions in htaccess. I know you can use in special situations, but I need something like: If a then b etc like in php. In other words I want to redirect the...
5
by: deko | last post by:
I'm trying to redirect requests for /index.php to /mydirectory/index.php If I use an index file in / with only this line: <?php header("Location:http://www.mysite.com/mydirectory/"); ?> that...
3
unicorn
by: unicorn | last post by:
hi, i want to prevent flashGet (or programs like this) from browsing my website and its content... is that possible? or if it is how... through .htaccess you can use rewrite engine like this: ...
9
by: invertigo | last post by:
Hello, Im using this .htaccess file to rewrite my websites URL. Reason i try to do this is to make it more SEO friendly. Code: -------------------------------------------------------- Options...
3
by: Joe | last post by:
Hello, I currently have a file system where images and assets are stored in a directory like this: http://www.domain.com/assets/media/CLIENT_NAME/uploads/CLIENT_DIR/CLIENT_FILES Which holds...
4
by: adnanjunk | last post by:
Hi, Having a little issue with .htaccess not working on windows server. I have clean url's setup using the htaccess file, working fine on linux server. I have researched for a while and found...
8
hsriat
by: hsriat | last post by:
I had a .htaccess file for Rewrite on my server and was working fine. Now when I used the same code in 1and1 hosting, its not working. May be something is wrong or unexpectedly good happening...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.