What I want to do may sound odd or strange way to do things but I have a reason for it and think it must be ralatively simple to do.
I can do simple .htaccess url rewrites (and to most what I need to do is probably simple) but I'm just struggling with how I want to construct it now.
I want the url to be constuctued as follows
mydomain.com/news/$date-$id
The date and id are stored seperately in the database and I want them connected with a "-" and not a "/" is that makes sence.
So the url will look something like
mydomain.com/news/050406-12
Anyone able to show me the correct way to get this right
I presume you want that URL mapped to a script that will accept the date and id as parameters? If that's correct, then assuming a script called news.php; your rule would look something like this:
Have been having a think and now unsure if I want the "-" in there now.
I thougth it would have been a very simple removal of the "-" from the rewrite code to sort it but doesn't seem to be the case.
Yes, the "-" was crucial to how that regular expression matched the date and the id separately. By removing it; there is no longer a demarkation, so the first bracketed expressesion would have captured everything. My guess is that the whole thing would have be passed to your news script as the date variable.
To get around this; and as long as the date will always be 6 characters long, you can use a fixed length matching pattern to pick up the date; and the match the remainder as the ID; like this:
another way around it is just have mydomain.com/news/050406-12
RewriteRule ^news/(.*) news.php?id=$1 [L]
then in the script
$info = explode("-", $id);
$info[0] = $date;
$info[1] = $id;
bit of a hack around, but works.
or use the better, clever solution provided above
__________________ Dan Morley Alpharooms.com
daniel at alpharooms dot com - Hotels, Flights, Airport Transfers, Care Hire + More! sign up My Blog | Cheap Holidays
Doesn't seem to. Maybe I should go with the way it was before which was preferable, only reason I was lookign to change is because I have some old news articles that have been published and I don't want to much google up with creating new URLS and duplicating the same stories.