Dynamic Permalinks
-
Hello. I have been working for the past few days, trying to figure out how to get this to work. I’ve gotten close, but not quite where I want to be.
I have an item database on my site, which is on a WP page (https://www.d3sanc.com/items/). I have it currently so instead of using an ugly link like “https://www.d3sanc.com/items/?id=65” it goes to “https://www.d3sanc.com/items/65/“. This will take you to item #65’s page, and display it’s information.
This is all fine and dandy, does exactly what I want it to do. But for SEO purposes, there is one more thing I would like to do, be able to add the item’s name to the link, like “https://www.d3sanc.com/items/65/Minor-Alabaster-Runestone/“.
I have spent many many hours trying to figure out why this won’t work, and I am stuck. Again, the links work perfectly fine if I just have “/items/##”. But if I try to replace the # with the item’s actual name (https://www.d3sanc.com/items/Minor-Alabaster-Runestone/), it redirects me to a 404 page. I don’t understand why it will work perfectly fine with numbers, but not if there are letters there. And for the record, yes I changed the code to work off item names rather than item IDs. The error has nothing to do with MY code, it is something to do with WP.
Ideally I would like to have it go “/items/###/Item-Name/”. But it appears that if I use letters anywhere in the URL after “/items/”, it glitches WP and takes me to a 404. And even if I just add the name at the end of the URL at the moment, it takes me back to “/items/”, as if there is no ID in the URL.
RewriteRule ^items/(.*)/$ items/?page_id=417&id=$1
That is the RewriteRule that I am using in the .htaccess. I have it add the page’s ID just as a safety precaution, as I’ve ran into a few problems where this actually fixed it.
I have tried the following (which makes perfect sense to me), but I still get the same errors that I mentioned above.
RewriteRule ^items/(.*)/(.*)/$ items/?page_id=417&id=$1&n=$2
To me, this makes perfect sense. It should work just as the above rule, except if it has another “folder” at the end of the url, it will take that information and put it in the “n” var.
Sorry, I know this is a really long post, but I’m just really hoping I can get some help with my problem. Thank you for your time.
- The topic ‘Dynamic Permalinks’ is closed to new replies.