WP Hive » Troubleshooting and How-To

Permalink URL's not working

(27 posts)
  • Started 3 years ago by lakong
  • Latest reply from Mbird
  • 3 Members Subscribed To Topic

Tags:


  1. lakong
    Member

    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

    Posted 3 years ago #
  2. lakong
    Member

    Hi, can someone please respond to this email?

    thanks

    Posted 3 years ago #
  3. ikailo
    Developer

    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.

    Posted 3 years ago #
  4. lakong
    Member

    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?

    Posted 3 years ago #
  5. apalm
    Member

    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

    Posted 3 years ago #
  6. ikailo
    Developer

    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.

    Posted 3 years ago #
  7. apalm
    Member

    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.

    Posted 3 years ago #
  8. apalm
    Member

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

    Posted 3 years ago #
  9. confuscius
    Member

    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!

    Posted 2 years ago #
  10. ikailo
    Developer

    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.

    Posted 2 years ago #
  11. andrewl
    Member

    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?

    Posted 2 years ago #
  12. ikailo
    Developer

    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!

    Posted 2 years ago #
  13. ikailo
    Developer

    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));
    Posted 2 years ago #
  14. ikailo
    Developer

    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?

    Posted 2 years ago #
  15. andrewl
    Member

    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…

    Posted 2 years ago #
  16. Timmie
    Member

    @ikailo You are doing a good job, well done!
    I have been finding this permalink issue slightly frustrating. I included the above code but there seems to be no effect apart from making one of my blogs disappear completely. Is there something I'm not doing right? Thanks

    Posted 2 years ago #
  17. ikailo
    Developer

    Timmie: Sorry, I haven't had an opportunity to test this completely, so I can't provide more insight. It is a more technical issue than it might appear - hopefully something that can be solved within time.

    Posted 2 years ago #
  18. sallam
    Member

    I'm using the new hp-hive version.
    Here is what's in my .htaccess before I add a new site:

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

    # END WordPress

    I'm using custom friendly URL

    /%postname%.html

    and here is my .htaccess after adding a new site:

    # BEGIN WordPress

    # END WordPress

    But, as andrewl mentioned above, the best solution so far is to make our htaccess file read-only when the last time we edited permalink is the way we want for all sites. Usually, if you prefer friendly urls, you'd want all your sites to use them the same way the original site does.

    Once I changed htaccess file permission from 644 to 444, new sites couldn't change anything in it. I only have to set the permalink in new sites to use the same custom friendly urls that I'm using in all other sites. It will complain that the file is not writable, but thats fine. Leave it at that. Firendly urls will work in the new site once you set it in permalink.

    The important advantage is that adding new sites will not mess current sites if we make the htaccess file's permissions set at: 444 (read-only), and we only have to do this once.

    Posted 2 years ago #
  19. ikailo
    Developer

    Hmmm... I had actually fixed this in 0.5. Concluded that the WP install function flushes the rewrite rules at the end of the install process and that the fix was to tell WordPress not to do it.

    If it's still clearing your .htaccess, then I'd hazard there's something wrong either with the WP Hive install, or WP is set up differently than I had expected.

    Is there anything about your WordPress configuration and/or install process that is 'non-standard'?

    Posted 2 years ago #
  20. jamesquin
    Member

    Was this issue ever solved as it is REALLY annoying. I have 60 blogs set up - ALL are set to custom permalinks and NOTHING has been changed in any permalinks settings. I have made the htaccess file read only. We are ONLY adding content and pages to blogs but EVERY single time we work on any site the htaccess file is overwritten (ie blank) and I have to paste the code back into the file. This means my sites are almost permanently down and I have to keep checking to see if the links are working.

    There has to be a permanent solution to this - I see several work around's but this does not appear to fix the problem or stop it keep happening. Any help or solution much appreciated as I am sure this is frustrating many more people.

    Posted 1 year ago #
  21. ikailo
    Developer

    Unfortunately, the only solution right now is to make sure .htaccess is read-only across the board: 555. If WordPress is overwriting, then you may have a 655 or 755 permission on it. I recommend you double check this.

    For the permanent solution, this ticket must be committed to core. At this time, it looks like it will be a while before that happens.

    Also, bear in mind that .htaccess can be flushed even when just LOADING the options-permalinks page in WP Admin. This ticket is intended to fix this behavior.

    Posted 1 year ago #
  22. jamesquin
    Member

    I have made htaccess read only - numerous times yet it is still overwritten!!

    Posted 1 year ago #
  23. ikailo
    Developer

    This is very strange behavior. Maybe you have a plugin that is forcing it to be writable?

    Neither WordPress or WP Hive attempts to change permissions on .htaccess. If WordPress finds that it is not writable, then it will advise you to make a manual update when you re-save the permalinks options.

    Are you on a Linux server?

    Posted 1 year ago #
  24. jamesquin
    Member

    Yes, Linux server. It is very frustrating

    Posted 1 year ago #
  25. ikailo
    Developer

    Can you send me the URL(s) of your site, via email?

    Posted 1 year ago #
  26. jamesquin
    Member

  27. jamesquin
    Member

    Still unable to resolve this. I confirm all settings are the same on each blog, htacces is set to read only and I've even disabled virtually all the plugins. It is VERY annoying and disrupting to my business. I'm looking to see if there are other viable alternatives to WPHive that will do what I want but save having this probem - any suggestions anyone?

    Posted 1 year ago #
  28. wwday3
    Member

    I posted this elsewhere, but I guess you can ignore that thread. I didn't see this thread.

    I was having the same issue as jamesquin. Sites were reverting to blank htaccess rules even when I did nothing to them (not even a visit - they are autoblogs). Modifying the htaccess permissions (to 555) does seem to protect the htaccess when I've tried that approach.

    This was not happening with older versions of wp-hive and prior to WP 3. Could it have something to do with the new multi-site characteristics of WP 3?

    It is not good to have a dozen sites - especially autoblog sites - suddenly stop working.

    Posted 1 year ago #
  29. Mbird
    Member

    Will there be a solution for this issue ever?

    Posted 1 year ago #

RSS feed for this topic

Reply

You must log in to post.