Actually, it's not the reverse that I want to do. Right now the pages on my site use this form of URL:
domain.com/articles.php?id=999 Now that I have upgraded my server to Apache 2, I'm going to use the ForceType and FollowSymLinks options to change the entire site to use this search-engine-friendly form of URL to access all pages: domain.com/articles/999 But I don't want the old links to be broken once I change the site to this new type of URL. So, if someone types in "domain.com/articles.php?id=999", instead of getting a 404 error, I'd like to use the RewriteEngine to rewrite that URL to the valid new URL format: domain.com/articles/999. So, I thought this would work in my .htaccess file, but it doesn't: RewriteRule articles\.php?id=([0-9]+) articles/$1 [R] Do I have to escape the ? before id \? I tried it, but it didn't make a difference. I also tried /articles... but that didn't work, either. Monty > From: [EMAIL PROTECTED] (Paul Chvostek) > Newsgroups: php.general > Date: Sat, 24 Jan 2004 13:39:25 -0500 > To: Monty <[EMAIL PROTECTED]> > Subject: Re: RewriteRule REGEX ? > > > On Sat, Jan 24, 2004 at 12:18:36PM -0500, Monty wrote: >> >> From This: articles.php?id=999 >> To This: articles/999 > ... >> What am I doing wrong?? > > I suspect you may not be looking at the problem the right way. > > What exactly do you want to do? > > Normally, you'd go the other direction; that is, you'd have mod_rewrite > recognize ^/articles/([0-9]+)$ and translate it to /articles.php?id=$1 > ... so that a request to the "pretty" URL gets served as an HTTP GET on > the PHP script. > > I get the impression that you're expecting mod_rewrite to translate copy > from inside your HTML files, as well as recognize and reverse the > translation when the request comes back in. Is that it? > >> RewriteEngine on >> RewriteRule ^articles\.php\?id=([0-9]+)$ articles/$1 [R] > >> But I keep getting a 404 error for articles.php, which means that something >> must be wrong with my RewriteRule because it's not matching. I've tried >> various tweaks and just can't get it to work. > > I bet if you create an "articles" directory in your documentroot, with > with files named things like "999" in it, you'll stop seeing the 404's. > Check your apache error_log. > > If what you're trying to achieve is to have existing HTML files get > their embedded URLs translated, you're going to have to do that with an > output filter. You can do it with PHP, or use mod_sed ... lots of > options. But a rewrite rule won't change page content, it'll only > rewrite the *requests* that come in. > > Of course, if you know all this already, and really are trying to point > requests for /articles.php?id=123 to a file named "123" in the directory > "articles", then you'll still need to inspect your error_log. > > -- > Paul Chvostek <[EMAIL PROTECTED]> > it.canada http://www.it.ca/ > Free PHP web hosting! http://www.it.ca/web/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php