...

View Full Version : Another simple url rewrite



thesavior
08-21-2006, 04:59 AM
I want to turn articles/4.html into news.php?id=4

Any ideas?

thesavior
08-22-2006, 08:11 AM
*bump*

thesavior
08-24-2006, 03:05 AM
*bump*

thesavior
08-30-2006, 02:41 AM
any ideas how to do this?

Rappa
08-30-2006, 06:55 AM
<?PHP
switch($id)
{
default:
echo "this is the default page";
case '4:
echo "put '4' content here";
break;
break;
}
?>

thesavior
08-30-2006, 07:10 AM
What? That is NOT an htaccess rewrite. If you missed the first post, i will repeat it.

I want a user to be able to put articles/4.html in their browser and it to be parsed by the server as news.php?id=4

I don't need to know how to display different material according to the id #. Using htaccess rewrite methods only, how do I do this?

thesavior
08-31-2006, 09:20 PM
does anyone know how to do this?

thesavior
09-02-2006, 10:32 PM
*bump*

googleit
09-03-2006, 12:34 AM
you cant do that with .htacces try this though

<?php
$action = $_GET['page'];

function yourfilename() {
include("yourfilename");
}
if ($page == "yourfilename") {
yourfilename();
}
?>

then you can make a link like index.php?page=yourfile
and it will display you file on the page

thesavior
09-03-2006, 01:02 AM
So why wouldn't something like this work?

RewriteRule ^articles/(.*).html$ news.php?id=$1 [L]

That should work but there is a syntax error in there somewhere and I don't know what is wrong.


*edit*

Actually, this does work. View: http://image-space.net/articles/4.html and http://image-space.net/profile/news.php?id=4

googleit
09-03-2006, 01:29 PM
if you knew how to do it y post a thread onit?

GJay
09-03-2006, 03:40 PM
you cant do that with .htacces try this though

yes, you can.

googleit
09-03-2006, 05:55 PM
k my bad :)

thesavior
09-03-2006, 07:24 PM
i just came up with that. I didn't know it at the begining of this thread

GJay
09-03-2006, 11:57 PM
the . probably needs to be escaped...

thesavior
09-04-2006, 07:14 AM
which dot?

GJay
09-04-2006, 09:08 AM
in the time it took to reply, you could have tried both...

thesavior
09-05-2006, 08:03 AM
well seeing as how it works without escaping, i don't see what the difference would be for escaping one of them.

schleppel
09-06-2006, 11:28 PM
Because if you don't escape the last dot to make it literal, it could match something other than a dot.

And if you're only matching numbers, you should use [0-9]+ instead of .*:

RewriteRule ^articles/([0-9]+)\.html$ /news.php?id=$1 [L]



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum