• D3Sanc

    (@d3sanc)


    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter D3Sanc

    (@d3sanc)

    I just noticed that it is somehow using the “id” of the item, as the page number, thus the reason for it not 404’ing on me when I just do “/items/##/”. But if I add another part to the end of the URL, or use letters/text instead of number, I get the error, since there can’t be a page number “Loltext”.

    I really wish I could figure this out, to help my SEO. *Sigh*

    fonglh

    (@fonglh)

    I’m not all that familiar with regex, but it looks like you’ve hardcoded a page id to the query and $2 will be getting a string.

    why don’t you just put /items/%post_id%/%post_name%/ into your permalink structure?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Dynamic Permalinks’ is closed to new replies.