Home › Forums › Archives › Computer Support › Computer Support Discussion › mod_rewrite and friendly urls
- This topic has 5 replies, 3 voices, and was last updated 17 years, 1 month ago by DrBroccoli.
-
AuthorPosts
-
January 26, 2007 at 5:00 pm #26254TigerbladeParticipant
Grr. I’m getting frustrated here. I’m attempting to play with htaccess to get friendly URLs, but I’m having no luck.
Some background: my site typically uses a URL like http://tigerblade.net/journal/?id=334 to load journal entries. What I want to do is get a friendlier URL like http://tigerblade.net/journal/2007/01/16/if-it-werent-for-my-horse/ to work. My intention was to have a PHP script that’s triggered anytime I write a new entry — it will process the date and title and add a line to the htaccess file.
I’ve followed a few instructions and such online, but I still can’t get it to work even though by all appearances it should. instead of a working page, i get an error 404.
here’s a sample from the .htaccess file:
Code:RewriteEngine On
Options +FollowSymLinks
RewriteBase /testRewriteRule ^/([/w])$ /test/$1/ [R]
RewriteRule ^/(d+)/$ /test/?id=$1RewriteRule ^/2007/01/16/if-it-werent-for-my/ http://tigerblade.net/journal/?id=334
I’m sure it’s something simple that I’m missing, but i can’t spot it. Help?
January 26, 2007 at 8:03 pm #157419DrBroccoliParticipantI just had this problem with my blog! I had pretty much the same .htaccess file as you, and mine never ended up working either. I tell you, I think it’s something on Dreamhost’s side, I couldn’t figure it out for the life of me.
I’m going to work on it a bit more today and see what I can get, sorry I couldn’t be more help (like I was any at all in the first place =D).
January 26, 2007 at 10:09 pm #157416TigerbladeParticipantgah… I found out the problem. I posted this same question over at the Boagworld forums (forums more specifically for web developers and designers and such) and analgesia pointed me in the right direction.
Code:RewriteEngine On
Options +FollowSymLinks
RewriteBase /journalRewriteRule ^2007/01/16/if-it-werent-for-my(/)? ?id=334
so simple. I don’t know what my problem was, really, but geez.
Brock… thanks for your answer. Hopefully now that mine’s solved you’ll find what the issue is with yours.
January 27, 2007 at 12:19 am #157415Jeff HesterKeymasterTigerblade, I hope you find a better solution than adding a new line to the .htaccess file for every blog entry. It’s probably not the most efficient method.
It would be better to use something more flexible. For example, you could append “-334” to the friendly URL and parse that to get the id. Then you could effectively do the same thing with one line in your .htaccess file.
January 27, 2007 at 12:58 am #157417TigerbladeParticipantjeff… whatever’s easiest and most efficient would be best. i’m basically just going for the same effect most established blogging software has — take your site for example.
using your most recent post (and the one linked in your signature), the URL is http://www.jeffhester.net/2007/01/21/my-first-ipod/
there’s no id tacked on that. how does WordPress handle that URL and properly fetch the post?edit: durr. i think i know a way to do it, and it wouldn’t be much harder than just modifying my existing code for loading an entry. it’d only take one line in the .htaccess file. i haven’t actually tried it yet (no time) but it should work.
January 29, 2007 at 5:14 pm #157418TigerbladeParticipantok, here’s a question. the following two lines appear to me to be practically identical in form. one uses literal characters, one uses RegEx character classes. the first works, the second fails. WHY?
Code:RewriteRule ^(2007/01/16/if-it-werent-for-my)(/)? /test/?id=$1RewriteRule ^((d{4})/(d{2})/(d{2})/([-w]+))(/)? /test/?id=$1
-
AuthorPosts
- You must be logged in to reply to this topic.