URL rewriting

· Comments (16)

I've looked at URL rewriting before and managed to implement something extremely dull (a very simple forward), but I can't really get my head around anything more complicated.

What I want to do is make sure that

http://prolific.org/?/archive/yyyy/mm/dd/title_of_article.html

gets forwarded to

http://prolific.org/archive/yyyy/mm/dd/title_of_article.html

Which probably isn't complicated at all. Except to me.

Tips?

Categories

16 Comments

ijsbrand said:

Are these URL's in HTML/XML- documents? Because, if it is just text that needs to be changed, most advanced HTML-editors can do this on lots of files with just one command.

Caroline said:

Sure, but what about outside links.

ijsbrand said:

Much depends on the rights you have to configure the web server here.

If possible, rewrite the httpd.conf file to create a virtual host.

[One such a script is given here:]
http://forums.devshed.com/t12731/s.html

If you don't have permission to tackle the httpd.conf, place a .htaccess file in the old directoy.

I don't have a link to the exact commands in such a file at hand, but it mustn't be that difficult to Google.

Caroline said:

I was looking for a .htaccess solution. Probably something like this: http://www.carlsoncarlson.com/dane/archives/2003/06/11/no_more_mod_rewrite_trouble.php

It's just that the whole /(.*) thing is just gobbledegook to me.

ijsbrand said:

As I understand it is just one line with three elements of code you need to use:

Redirect /olddirectory/oldfile.html http://yoursite.com/newdirectory/newfile.html

The first element is the command "Redirect", the second is the relative link to the old file, and the third the full URL of the other file. There has to be a single space between the three elements, and they need to be on one line.

Hope this helps.

Caroline said:

That's not what I mean. I know how to rewrite a single URL. I'd like one rule to redirect all urls. Any address of the format mentioned in the original post.

drunkmen said:

You can't use mod_rewrite for this, the argument part of the url (after the question mark) isn't parsed by mod_rewrite. You could use a script on your document index to do this (perl, php, etc.).

However, you probably want to do it the other way around, which seems more reasonable, i.e. point:

http://prolific.org/archive/yyyy/mm/dd/title_of_article.html

to:

http://prolific.org/?/archive/yyyy/mm/dd/title_of_article.html

To do so put this in .htaccess:

RewriteEngine on
RewriteRule ^(archive/[0-9]{4}/[0-9]{2}/[0-9]{2}/[^/]*)$ ?$1 [L]

Caroline said:

Hmm. I used to have a template index which I used to show the archives in but I'm no longer doing that. Everything's static. So it's the other way around.

There doesn't seem to be a simple solution then. Thanks for the help!

drunkmen said:

Still not sure why you would want this: if you somehow can put a _dynamic_ url with a question mark in your _static_ archive index, why can't you put one in it without the question mark?
You should get rid of this KnowSpam.net stuff on a comments form though, it's quite offensive.

Caroline said:

Sorry, I thought I'd already fixed that Knowspam thing. Too many sites, too many forms, too little time.

Caroline said:

You know what, never mind the URL rewriting. I can't seem to explain what I'm trying to do.

drunkmen said:

No problem, hth. But I still can't see the purpose: a question mark in an url implies a dynamic page hence you can use a script. Is this to disclose your archive?

drunkmen said:

No problem, hth. But I still can't see the purpose: a question mark in an url implies a dynamic page hence you can use a script. Is this to disclose your archive?

Caroline said:

My archives used have the ? in it, but they no longer do. I took it out because it complicated stuff with MT. Now I want to make sure people who bookmarked the /? links end up on the right page.

drunkmen said:

Ah, that explains it. You could do this, if php is supported.

Rename your old index.html (or whatever) to old_index.html. Create an index.php file with this in it:

<?PHP

if (reset($_GET) == '') {
$a = key($_GET);
if (substr($a, 0, 9) == "/archive/") {header("Location: {$_SERVER['HTTP_HOST']}$a");exit;}
}
echo implode('', file('old_index.html'));

?>

Caroline said:

Thanks, I'll play with that.

About this Entry

This page contains a single entry by Caroline published on February 6, 2004 3:41 PM.

VD: fat, naked, dangerous was the previous entry in this blog.

Of questions and blinkers is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.