Permalink URL’s not working

Home Forums Troubleshooting and How-To Permalink URL’s not working

Tagged: 

This topic contains 28 replies, has 10 voices, and was last updated by  Mbird 6 years, 9 months ago.

Viewing 15 posts - 1 through 15 (of 29 total)
  • Author
    Posts
  • #416

    lakong
    Participant

    I am using custom URL permanlinks on my main blog in the form:

    /%category%/%postname%/

    When I first installed HIVE it didn’t work and apache returned page not found errors. However, I realized that I hadn’t installed the plugin yet. Once I did it worked fine. However, today, even with the plugin installed, the links don’t work. If I use the default permalink format things work fine, but I don’t want to do this.

    Any ideas?

    – S

    #761

    lakong
    Participant

    Hi, can someone please respond to this email?

    thanks

    #762

    ikailo
    Participant

    If you have any other plugins installed, please deactivate them and try it with only wp-hive plugin installed.

    Also, refresh your permalinks by visiting and saving the wp-admin > settings > permalinks page.

    I have to admin, this one has me a little stumped so far, but please let me know if either of these ideas work.

    #763

    lakong
    Participant

    I did some testing. If I go to settings/permalinks and re-save the settings, everything works. I tried a few of the permalink options and everyone results in a broken link once I add a new website. So I have to go to each of my hive sites and resave the permalinks after installing a new site to the hive. Any ideas or things I should try to help you narrow the issue?

    #832

    apalm
    Participant

    Hi,

    this is a major headache for me as I am a domain name investor and tend to buy a few domain names per month and then add to the hive. But as I have the same problem as described above, I have to go to each and every one of my 40+ sites. I am running WP 2.7 and would be willing to put down a $50 donation for this to work, if you want to throw in a superadmin user that can log in to all blogs, that would be awesome as well.

    Cheers.

    Anders

    #837

    ikailo
    Participant

    Thanks for the offer. The solution is in the works (I understand how to do it), but I haven’t had the time to do any actual coding recently. I will get to it ASAP.

    If there are any developers out there who would like to take this on, please feel free to contact me to discuss.

    #845

    apalm
    Participant

    Great news! maybe you can drop me an email at anders at apalm.se when done, then I will send you the $50. Thanks for a great plugin.

    #846

    apalm
    Participant

    Btw, I would love to help out but my PHP skills will not make anyone happy =)

    #881

    confuscius
    Participant

    Could someone please explain in more detail the series of events that lead to this particular issue.

    As I also understand it for the robots.txt and favicon.ico to work properly then it is necessary to save the permalinks to force the addition of the rewrite rules.

    Why does adding a new domain to the hive mess up already added domains and why is it necessary to resave all permalink structures?

    If I can understand the issues then I may be able to work out a fix!

    #882

    ikailo
    Participant

    It’s necessary to re-save the permalink structure because the rewrite rules need to be flushed when changes are made to it. This process writes the rules to the .htaccess file and also caches them to the database.

    I can’t say I understand for sure why it needs to be updated for each site, but it likely has to do with the fact that .htaccess is shared for each site, and possibly also that each options table (which are independent for each site) contains a cached copy of the rules.

    #948

    andrewl
    Participant

    Ikailo and all,

    I have just been through exactly this situation and would like to help formulate a solution. The issue stems from the fact that there is only one .htaccess file for the whole wordpress installation (in the main wordpress directory) and that .htaccess file is therefore used when rewriting URLs for ALL blogs in the hive.

    If you have ANY blogs that use friendly style permalinks then wordpress writes a section of code into the .htaccess file to rewrite those friendly URLs. It does this when you CHANGE the permalink settings

    The trouble arises when you install a new blog into the hive – the default permalink setting is to use query string (‘?’) style permalinks – and installing the new blog REMOVES that section of code from the .htaccess file.

    The workaround that I used is, immediately after installing a new blog into the hive, go to ANY settings/permalinks page and resave the settings to use friendly permalinks – that reinstates the code in .htaccess (as far as I can see, it’s the same code for ANY permalink rewriting).

    But, I agree this is a pain as it stands – and presents a high risk of seriously breaking the whole hive if you forget to do it. The first I noticed it was after installing my second blog the whole of the first blog was broken – minor panic set in until I figured it out.

    One way to prevent the hive wipeout scenario is to set the perms on .htaccess to read-only (a good idea in general) once you’ve set up the first blog with friendly permalinks. Subsequent blog installations will complain about not being able to write .htaccess, but that can be ignored.

    So, Ikailo, did you have an idea of how to approach this more generically? If so, maybe I can help out by experimenting?

    #949

    ikailo
    Participant

    andrewl, thanks very much for providing this definitive answer. I was thinking that the issue was related to this, and I appreciate your research.

    One of the things the new version will do is to provide a more robust method for activating the plugin, which will specifically flush the rewrite rules (the same as saving the permalinks) after the blog is installed.

    In the meantime, I put together this code that ‘should’ do the trick (it’s untested, so your feedback is appreciated).

    Add this to the end of wp-hive.php:

    // flush the rewrite rules
    function hive_rewrite_flush() {
    $rewrite_flushed = get_option('wphive_rewrite_flushed');
    if (empty($rewrite_flushed) {
    global $wp_rewrite;
    $permalink_structure = '/%category%/%postname%/'; // set this to your default structure
    $wp_rewrite->set_permalink_structure($permalink_structure);
    $wp_rewrite->flush_rules();
    add_option('wphive_rewrite_flushed', 1)
    }
    }
    add_action( 'generate_rewrite_rules', 'hive_rewrite_flush');

    Note: This assumes that your default permalink structure should be “/%category%/%postname%/”, so you may want to change that, depending on your preference.

    Let me know if it works!

    #950

    ikailo
    Participant

    Hmmm.. Just re-reading your post, and I’m not 100% sure that my code will do the trick. You mentioned that it removes the rules because the default permalink structure is the ‘?’, so we may actually need to CHANGE the permalink structure from the default.

    I would experiment with this, replacing the portion inside the if block above with:

    global $wp_rewrite;
    $permalink_structure = '/%category%/%postname%/'; // set this to your default structure
    $wp_rewrite->set_permalink_structure($permalink_structure);
    $wp_rewrite->flush_rules();
    $wpdb->query ($wpdb->prepare("INSERT INTO wphive_config (item, val) values ( %s, %s )", "rewrite_flushed", 1));

    #951

    ikailo
    Participant

    Also, I think this brings up another issue, which is that every site in the hive SHOULD be configured to use identical permalink structures, otherwise the permalinks will always take on the structure of the last site for which the rewrite rules were flushed. Can anyone confirm this?

    #959

    andrewl
    Participant

    Yes, this last point about every blog using the same permalink structure is an interesting one. Initially I also believed that this would be necessary but now I think not.

    By default, wordpress uses URLs of the form …/index.php?p=123 to display posts. The index.php file parses the query string and finds the right post to display. Note that there is no requirement for any .htaccess directives for the default permalink structure to work because all references for pages go via the file index.php which does exist.

    If you configure friendly permalinks, like …/2009/04/123 then the file referenced by the URL (in this case a file called ‘123′ in the directory 2009/04) does not exist. To make this work, wordpress writes a set of rewrite directives to .htaccess that has the effect of saying “if you get a reference to a file that doesn’t exist then pass it to index.php anyway”. So, the URL of 2009/04/123 invokes index.php which in turn parses the URL to work out what page to serve.

    What this all means in practice is simply that if ANY blog uses friendly permalinks then you MUST make sure that .htaccess contains the rewrite directives (note, the directives are the same for ANY style of friendly permalink). But if no blog uses friendly permalinks then you don’t HAVE to have the rewrite directives – BUT, nor is it a problem if you do – because a reference to index.php?p=123 will not invoke the rewrite rule and so will work as required.

    So, we don’t HAVE to force a particular permalink structure on new blogs – logically, all we have to do is to make sure that .htaccess is PRESERVED when a new blog is installed to the hive – but I’m not sure yet how to arrange that in practice. I’ll take a look at the code above and see how that goes

    Hope this helps…

Viewing 15 posts - 1 through 15 (of 29 total)

You must be logged in to reply to this topic.