WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Changing the Permalink structure, should I..? (16 posts)

  1. spencerp
    Member
    Posted 8 years ago #

    So, I guess I'm basically calling for all the Permalink "Professionals" on this one lol. [Cough]Whooami, maybe a few others.. =P

    Here's the deal, I've basically had this permalink structure for some time now: /%postname%.htm

    And was thinking about changing it to something like this maybe: /id/1234 or /1234

    The question is, is there away to use the first choice of: /id/1234, or either way really.. without having to add tons of redirects in the .htaccess file?

    What I'm afraid of though, is those that maybe had "saved", bookmarked, or even done trackbacks to the articles.. =/ I'd hate to lose those people or screw up their "saved" whatevers.. =/

    Sean Hayford O'Leary was telling me on GoogleTalk the other night, that's what he had to do basically.. so those people wouldn't be "lost".

    His suggestion was merely a suggestion, so those who wanted to type up an article's URL, might be a little easier to remember the number of it, rather then the words for it.. =/

    What do you all think is maybe the best thing to do? Leave it as is, or change it up? I'm just not sure what to do at this point sigh. =(

    spencerp

    I could have also tried this all out on the localhost, but figured why bother, when I could just ask the question on here quick.

  2. spencerp
    Member
    Posted 8 years ago #

    Hmm, I thought people usually jump, hop and skip on topics like this lol!! Oh well lol.. Much thanks goes to Sean again for doing this little PHP script, and Mod_rewrite rule up for me lol. =)

    <?php
    mysql_connect("dbHost", "dbUser", "dbPass") or die("connect failed");

    mysql_select_db("dbDatabase") or die("can't get to the database");

    $result = mysql_query("SELECT ID FROM wp_users WHERE post_name = '".addslashes($_GET['q'])."';")
    while($row = mysql_fetch_assoc($result)) {
    foreach($row as $var => $val) {
    $post = $val;
    }
    }
    mysql_free_result($result);

    header("Location: /archive/".$post);
    ?>

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.+).htm /wp-content/themes/specerp/wp-newuri.php?q=$1 [QSA,L]
    </IfModule>

    I didn't try it yet though sigh, but will soon. Jeremy Visser did though, said he got 404's for the pages, but that's expected I guess lol. Welp..going to try it on the localhost once.. see what happens.

    spencerp

  3. JeremyVisser
    Member
    Posted 8 years ago #

    Actually, I was commenting about Sean's theme being partially broken at the time. I haven't actually tested this! *spencerp gulps*

  4. spencerp
    Member
    Posted 8 years ago #

    Hahaha.. hells no! =P Well, I'll just try her out on the localhost first anyways.. so it's all good. ;) [Lights up a Marlboro]

    spencerp

  5. spencerp
    Member
    Posted 8 years ago #

    Well damn, I didn't mean localhost, I meant the other "live" blog I got, for crap testing purposes lol. I never did get that /%postname%.htm permalink structure working on the localhost sigh.. =(

    I'll try it then after IE7 Beta3 gets done downloading..

    [slaps self] Wake up spencer!!

    spencerp

    [wonders..] Maybe I should have a beer or two here and there lol.. always did think better a little drunk hahaha..

  6. JeremyVisser
    Member
    Posted 8 years ago #

    OK, here's the updated code I tested. Fixed a missing semicolon and added a 301 redirect to help with the PageRank(tm).

    This code is presuming that he previously used a permalink structure of /%postname%.htm and now wants to change it to /archives/%post_id% without breaking the links.

    The following is the code for /wp-content/themes/spencerp/wp-newuri.php (Note: replace spencerp with the real theme name.)

    <?php
    mysql_connect("localhost", "user", "password") or die("connect failed");'

    mysql_select_db("database") or die("can't get to the database");

    $result = mysql_query("SELECT ID FROM wp_posts WHERE post_name = '".addslashes($_GET['q'])."';");
    while($row = mysql_fetch_assoc($result)) {
    foreach($row as $var => $val) {
    $post = $val;
    }
    }
    mysql_free_result($result);

    header("HTTP/1.1 301 Moved Permanently");
    header("Location: /archives/".$post);
    ?>

    And the .htaccess file:


    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+).htm wp-content/themes/spencerp/wp-newuri.php?q=$1 [QSA,L]
    </IfModule>

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

  7. spencerp
    Member
    Posted 8 years ago #

    Haha, you're awesome for testing it, and modifying it man! =) Atleast *someone* isn't afraid to help me lol! Thanks again Jeremy. ;)

    spencerp

    I think it sad that no one could even post an opinion or suggestion.. wtf!? I'm not that bad am I lmao!! Double checks for diseases and crap.. nope, don't have any.. Whatever..

  8. whooami
    Member
    Posted 8 years ago #

    oops! sorry spencer :P do it, do it this weekend!! you know you want to!!

  9. Chris_K
    Member
    Posted 8 years ago #

    I think it sad that no one could even post an opinion or suggestion.. wtf!?

    Didn't want to intrude as I'm not "whooami or a few others." Glad you got something sorted out. Keep us posted.

  10. spencerp
    Member
    Posted 8 years ago #

    Didn't want to intrude as I'm not "whooami or a few others." Glad you got something sorted out. Keep us posted.

    Aww..come on Handy lol, you *are* part of the "few others" lol. =) ;) You're always welcome to reply to anything I thread about or whatever. ;) I shouldn't have added that little bit I guess sigh. =(

    Like I said though, you're always welcome to reply, you're one of the "best" people to get answers from, for these types of questions. ;) Goes for *alot* of other people too. =P

    spencerp

  11. spencerp
    Member
    Posted 8 years ago #

    oops! sorry spencer :P do it, do it this weekend!! you know you want to!!

    Hahaha..it's ok lol. =P Yeah, I'll prolly change it all up either tonight or tomorrow. ;) I was kind of thinking about just doing it, when I upload the "new" theme I'm working on, but that might be a while from now..plus, my as well get the "permalinks" changed *now*, so they get settled in and all lol.

    But, I'll keep ya'll posted. =)

    spencerp

  12. spencerp
    Member
    Posted 8 years ago #

    I think I'll change this to "resolved" now..there really isn't any need to keep it "tagged" as "unresolved", or whatever.. ;)

    Also, if I have problems with the above script and mod_rewrite. I could always just hit Sean or Jeremy up on GoogleTalk, or something.. =P

    spencerp

  13. spencerp
    Member
    Posted 8 years ago #

    Just updating everyone on this..lol. That script, and .htaccess mod_rewrite above..works!! =)

    I just changed my permalink settings now..uploaded that
    wp-newuri.php file to the root, and added the mod_rewrite rules.. of course to point for the "root" directory..and the redirecting works and the /id/%post_id% permalink settings work just nicely.. =)

    This:
    http://www.vindictivebastard.net/every-mans-dream-bathroom.htm/

    *Still* takes you to the proper place..of this:
    http://www.vindictivebastard.net/id/287

    Now! I have *not* tried everything possible, so please keep that in mind, if anyone feels like testing a few things, feel free and let me know here. ;) However, there was a tiny glitch with the above "script" codes and I'll post the proper ones in the next reply..

    spencerp

  14. spencerp
    Member
    Posted 8 years ago #

    For your .htaccess file, for being on the *root* of the domain name, here below is what I used, in the .htaccess file.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+).htm wp-newuri.php?q=$1 [QSA,L]
    </IfModule>

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress

    Then for the wp-newuri.php file. Uploaded to the *root* of your domain.

    <?php
    mysql_connect("localhost", "DATABASE-USERNAME", "DATABASE-PASSWORD") or die("connect failed");

    mysql_select_db("DATABASE-NAME") or die("can't get to the database");

    $result = mysql_query("SELECT ID FROM wp_posts WHERE post_name = '".addslashes($_GET['q'])."';");
    while($row = mysql_fetch_assoc($result)) {
    foreach($row as $var => $val) {
    $post = $val;
    }
    }
    mysql_free_result($result);

    header("HTTP/1.1 301 Moved Permanently");
    header("Location: /id/".$post);

    ?>

    As in the above one, this line here:
    or die("connect failed");'

    Spit out a T-STRING error message on redirecting..because the little: " ' " at the end had to be removed..like this:
    or die("connect failed");

    I hope this might help someone else.. =)

    spencerp

  15. spencerp
    Member
    Posted 8 years ago #

    Another update.. thanks to Sean.. I had to add this in the .htaccess file, so the "catagory" links will redirect properly too. =)

    This:
    http://www.vindictivebastard.net/category/whatever/

    Now goes here:
    http://www.vindictivebastard.net/id/category/whatever/

    Adding this line:
    RewriteRule ^category/(.+)$ /id/category/$1 [R=301,L]

    To the first mod_rewrite block, like such:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+).htm wp-newuri.php?q=$1 [QSA,L]
    RewriteRule ^category/(.+)$ /id/category/$1 [R=301,L]
    </IfModule>

    I'm sure there is more things that need accounted for though, will keep this updated then.. ;)

    spencerp

  16. Christopher J. Hradil
    Member
    Posted 7 years ago #

    Just throwing .02 in on this one;

    I think it sad that no one could even post an opinion or suggestion.. wtf!?

    i think it boils down to when the forum 'supporters' (regular question answerers/moderators/etc) are stumped on something, in a general sense, one of two things happens, either, there's just no one out there with better information, or folks feel intimidated posting an answer.

    i'm going to start up a thread on a similar topic (which I've sent in to wp-hackers already) and I've got the feeling based on past experiance that it won't get much response.

Topic Closed

This topic has been closed to new replies.

About this Topic