Reputation: 919
We have two Wordpress (3.5) blogs in a network setup. We recently installed the Custom Permalinks plugin, https://wordpress.org/plugins/custom-permalinks/. It all works fine locally (Mac) and even on production for one of the blogs. For the other blog however, changing the URL slug using the Custom Permalinks plugin, gives: "This webpage has a redirect loop". If it makes any difference (even though it shouldn't) the blog is in Arabic and the posts' URL slugs are in Arabic. I have tried:
- Just going to the permalinks admin pages and hitting "Save", it worked for some people with similar issues.
- Tried to clear cache and cookies.
- Checked .htaccess
UPDATE
If this makes any difference, I noticed that on one of the blogs on our production set up, for which I get the "too many redirects" error, if I switch to using English URL slugs, it works. This blog is in Arabic, and we are using Arabic URL slugs.
I am running out of ideas, any help would be much appreciated, thanks!
Upvotes: 1
Views: 700
Reputation: 372
Problem is caused by the custom permalink (edited in post itself) having characters invalid for the plugin logistics (even spaces).
The plugin registers a hook:
add_action( 'template_redirect', array( $this, 'make_redirect' ), 5 );
template_redirect occurs during template load, as provisioned by the plugin's hook into add_filter( 'request', array( $this, 'parse_request' ) );
.
Due to plugin not supporting encoded url's, it fails to perform the database query.
The fix was fairly simple enough.
Adding urldecode()
to the spots required for proper logistics.
/frontend/class-custom-permalinks-frontend.php
Line # 167 becomes:
$request_no_slash = preg_replace( '@/+@','/', urldecode(trim( $request, '/' ) ));
Line # 369 becomes:
$request_no_slash = urldecode($request_no_slash);
Line # 432 becomes:
substr( urldecode($request), 0, strlen( $custom_permalink ) ) != $custom_permalink
Line # 440 becomes:
if ( substr( urldecode($request), 0, strlen( $original_permalink ) ) == $original_permalink
Line # 441 becomes:
&& trim( urldecode($request), '/' ) != trim( $original_permalink, '/' )
solved for me instantly.
Upvotes: 0