WordPress.org

Ready to get started?Download WordPress

Forums

Permalink Editor
trailing slash breaks permalink editor after version 0.2.7 (13 posts)

  1. locomo
    Member
    Posted 2 years ago #

    great plugin!

    ran into an issue starting after version 0.2.7

    with 0.2.7 I can have pages with a permalink structure that includes a trailing slash, but starting with 0.2.8 and into the current version 0.2.10 using a trailing slash results in a 404 error .. if i remove the trailing slash it works

    love to upgrade to the most recent version to take advantage of the speed improvements you've made but i'd like to keep my URL structure consistent with the trailing slash ..

    http://wordpress.org/extend/plugins/permalink-editor/

  2. Steve
    Member
    Plugin Contributor

    Posted 2 years ago #

    Hi,

    Thanks for your feedback on the plugin.

    Just a few quick questions to help debug the issue:

    1. Are you referring to the global page permalink structure, or the custom permalink set on an individual page basis?
    2. Can you provide an example of the permalink value you are using?

    Hopefully this should help debug the issue.

    Thanks,
    Steve

  3. locomo
    Member
    Posted 2 years ago #

    In my global settings, say for page permalinks I have:
    /%pagename%/

    and this is the behavior

    in 0.2.7 both of the following URLs work:
    http://abc.com/my-groovy-page/
    http://abc.com/my-groovy-page

    in 0.2.10
    http://abc.com/my-groovy-page/ == 404 error
    http://abc.com/my-groovy-page == works

    ideally, what i would like to see happen is if the trailing slash is ommitted, that the url gets rewritten to include it (and not show a 404 error)

    thanks

  4. locomo
    Member
    Posted 2 years ago #

    my out of the box permalinks structures work as indicated above:

    /%postname%/

    http://abc.com/my-groovy-post

    gets rewritten to:

    http://abc.com/my-groovy-page/

  5. Steve
    Member
    Plugin Contributor

    Posted 2 years ago #

    Thanks for posting those examples.

    Annoyingly I haven't been able to replicate this issue on my development install of WordPress.

    This may be an issue similar to those that others are having related to permalinks not correctly being regenerated.

    One thing you can try in version 0.1.10 is editing line 88 of index.php and adding a parameter to the generate_rewrite_rules() call so the line looks like so:

    if ( $this->generate_rewrite_rules( true ) ) {

    It's a bit of a long shot, but could I ask you to give this a quick try?

    - Steve

  6. amitraichandani
    Member
    Posted 2 years ago #

    I was facing the same issue. I tried implementing the quick fix you mentioned, but it doesn't work. Any work around to the trailing slash issue?

  7. locomo
    Member
    Posted 2 years ago #

    @36flavours .. tried your fix but no luck

  8. harrisonca
    Member
    Posted 2 years ago #

    I seem to be facing the same/similar issue as well.

    If my custom permalink contains a trailing slash, I get a 404 error no matter how i access the page.

    If I remove the trailing slash from the custom permalink, then both URLS (with and without trailing slash) then work.

    How do I set a custom permalink with a trailing slash but WITHOUT a file extensions like: /laws/CA/

    I have a reproducible case on my development blog. Would be happy to give access to help figure this out.

  9. harrisonca
    Member
    Posted 2 years ago #

    I don't think it is a flushing issue with the cache. I tried saving the post as well as saving in the Settings->Permalinks page to force the flush. I also tried editing the index.php file with the fix mentioned above. None seem to work.

  10. harrisonca
    Member
    Posted 2 years ago #

    This isn't the cleanest of code, but it seems to have solved my issue, hopefully not introduced new ones.

    Main problem was that get_post_by_custom_permalink function seemed to always remove trailing slash when trying to lookup custom permalinks. So it is no real wonder why trailing slash permalinks are never found.

    /**
    	 * Fetch a single post based on the custom permalink value stored as custom
    	 * meta data.
    	 *
    	 * @param string $permalink
    	 */
    	function get_post_by_custom_permalink( $permalink, $exclude = false, $suffix = '' )
    	{
    		$post = false;
    		if ( $front = $this->front() ) {
    			$permalink = str_replace( $front, '', $permalink );
    		}
    
    		// Fetch all the public post types to lookup against...
    		if ( $post_types = get_post_types( array( 'public' => true ), 'names' ) ) {
    			if ( $posts = get_posts( array(
    				'post_type' => $post_types,
    				'meta_key' => '_' . $this->tag . $suffix,
    				'meta_value' => $permalink,
    				'posts_per_page' => 1,
    				'exclude' => $exclude
    			) ) ) {
    
    				$post = array_shift( $posts );
    
    			} else if ( substr( $permalink, -1 ) != '/' ) {
    				// Lookup with a slash appended, just in case...
    				$post = $this->get_post_by_custom_permalink(
    					trailingslashit( $permalink ),
    					$exclude,
    					$suffix
    				);
    
    			} else if ( substr( $permalink, 0, 1 ) == '/' ) {
    				// Lookup without a slash prefix, this is the ideal behaviour
    				// however the above is required for backwards compatability.
    				$post = $this->get_post_by_custom_permalink(
    					ltrim( $permalink, '/' ),
    					$exclude,
    					$suffix
    				);
    
    			} else if ( substr( $permalink, -1 ) != '/' ) {
    				// Lookup with a slash appended, just in case...
    				$post = $this->get_post_by_custom_permalink(
    					trailingslashit( $permalink ),
    					$exclude,
    					$suffix
    				);
    			}
    		}
    		return $post;
    	}
  11. Steve
    Member
    Plugin Contributor

    Posted 2 years ago #

    Hi,

    I've taken a look at your modifications and made some alterations to the plugin.

    Could you try using the development version and see if this works for you as expected?

    http://downloads.wordpress.org/plugin/permalink-editor.zip

    (The version number shown in index.php should be 0.2.11)

    If this works, I'll tag and release 0.2.11.

    Thanks,

    - Steve

  12. harrisonca
    Member
    Posted 2 years ago #

    It does work, however we are missing a checking case. I don't know the code too well, but it seems like before if let's say it was looking for path like: /abc/def

    This current dev version would check:

    /abc/def
    /abc/def/
    abc/def

    The currently released code checks:

    /abc/def
    abc/def
    abc/def/

    But not the case /abc/def/

    So i'm not sure whether it is necessary to keep the case to check for "abc/def/".

  13. Steve
    Member
    Plugin Contributor

    Posted 2 years ago #

    Hello again!

    Thanks for testing that out.

    I've made some additional alterations to the plugin, but haven't had a massive amount of time to sit and think about it.

    The dev version should now check:
    /abc/def/ (forced to have both slashes)
    /abc/def
    abc/def
    abc/def/

    I've tested very briefly, but not extensively. There is also some additional support for utf-8 characters, which I hope hasn't caused any bugs to creep in.

    - Steve

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic