...

View Full Version : mod-rewrite gives me http://localhosthttp://localhost/...



me'
03-27-2004, 04:08 PM
I'm using the following RewriteRules to generate nicer URIs for my blog, but I'm running into problems:
RewriteEngine On
RewriteBase /
RewriteRule ^http://localhost/archives/?([0-9]{4})?/?([0-9]{1,2})?/?([0-9]{1,2})?/?([0-9a-z-]+)?([0-9]+)?/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&page=$5 [QSA]
RewriteRule ^http://localhost/archives/category/?(.*) /index.php?category_name=$1 [QSA](I don't actually understand .htaccess, this was generated by WordPress for me).

However, when clicking on a link that would normally take me to http://localhost/index.php?id=7, it's rewritten to http://localhosthttp//localhost/archives/2004/03/26/header-test. I thought it odd that the second http://localhost doesn't have a colon... could that be relevant?

TIA.

joh6nn
03-27-2004, 07:30 PM
i've also been messing around with mod_rewrite just recently, and although i'm nothing close to sure, i think that you don't want the http://localhost bit in there. try it as this:


RewriteEngine On
RewriteBase /
RewriteRule ^archives/?([0-9]{4})?/?([0-9]{1,2})?/?([0-9]{1,2})?/?([0-9a-z-]+)?([0-9]+)?/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&page=$5 [QSA]
RewriteRule ^archives/category/?(.*) /index.php?category_name=$1 [QSA]

me'
03-28-2004, 11:39 AM
Yeah, that was my first stab too, and it doesn't work. I still get the same link. Thanks for trying.

joh6nn
03-28-2004, 12:32 PM
yeah, i think your answer is gonna be a combination of things, though i don't know which combination.

the other thing you might try is dropping the [QSA] from the end; that messes with url query strings in ways that i won't pretend to completely understand, but i'm about 90% you don't need it.

also, for the time being, try commenting out the regular expressions, and see if it works with a single page. like


RewriteEngine On
RewriteBase /
RewriteRule ^archives/example.htm$ /index.php?example

then, if that works, try using a really simple RegEx, like maybe just ^(.*)$, see if it works, and work up from there. it will most likely turn out to be a terribly giant pain in the butt, but it's what i ended up doing. from the tutorials and docs that i've read, this is more of an art than a science, so a huge pain in the butt is the best you can hope for.

me'
03-28-2004, 12:35 PM
Well, after thinking about this a bit more, I figured it wasn't Apache's fault, the faulty URI was in fact being written straight into my page. I hopped through WordPress's function files and found the function. After a bit of editing, I found that WordPress was in fact, perfect, and it was my fault — I had my permalink options set up wrong :o.

For future reference: those of you using WordPress's fancy mod-rewrite URL functions, don't include your base url (eg http://localhost/ for me) when creating the 'virtual site structure' under Permalink Options, in options.

joh6nn, thanks for your help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum