Prevent WordPress home page redirect after WP 4.4.1 - wordpress

The WP is redirecting the home page to the home_url (or site_url not sure since both are the same values) even when arrived to the page using the parked domains. This started after the recent update. Also, I confirmed, no htaccess, server configs nor any plugins doing the redirect.
After thorough research the solution I found are placing the following in the functions.php remove_action('template_redirect', 'redirect_canonical');. That solution is years old and don't seem to work anymore.
The way I set it up is I park the domains to the WP site, and the contents displayed are based on the domain. Just happens on the index page, if it has any urls appended, it works. Any help is appreciated.

It looks like the new version of the WP enforced the redirect on homepage. My issue was resolved with the remove_filter('template_redirect','redirect_canonical');. I wasn't able to see the change in effect after I applied that fix because the browser cached it somehow. I tested it on the Private mode, and it worked. I had to clear the cache to see it working.

I ran into the same issue and got i fixed, thanks to your answer. However, what are the implications of removing that filter? It sound important by name, so did you experience some new issues so far?
PS: i would have posted a comment to the previous answer, but my stackoverflow points are below 50...

LTDInvestments is actually correct. In your wp-config.php, ensure that 'WP_HOME' and 'WP_SITEURL' have values which are lowercased.
This fixed it for me; I guess case-sensitivity is something you should mind throughout your wp-config.php and wp-admin settings.

This works for me (as for version 5.9.3):
add_filter( 'redirect_canonical', 'disable_redirect_canonical', 10, 2 );
function disable_redirect_canonical( $redirect_url ) {
return false;
}
Note: this removes redirecting for urls that partly match slug of content that exists for example domain.com/terms will no longer redirect to domain.com/terms-and-conditions but instead return a 404 page.

Also changing the WordPress Address (URL) and Site Address (URL) to all lower case works.

Related

301 Redirect only Posts not Pages

I am looking to redirect all the posts and not pages and custom post types from old domain to new domain. So all posts for instance
http://www.example.com/post1 should go to http://example1.com/post1
http://www.example.com/post1 should go to http://example1.com/post1
The pages i.e. http://www.example.com/page1 should still be functional
I can find alot of answers on moving blog into sub directory along with moving all the links but not for moving just the posts and not the pages
Edit
There are over 1000 posts so I am looking for a dynamic way of doing this
Thank you for your help
The hack I finally end up using was
Add ob_start to single.php as first line even before get_header()
Add following code in functions.php
change example.com with your site domain name
add_action('wp_head','redirectme');
function redirectme() {
if ('post' === get_post_type()){
wp_redirect( 'http://example.com' . $_SERVER['REQUEST_URI'] , 301 ); exit;
}
}
I don´t think this is possible with this URL schema. .htaccess (or the Apache behind it) doesn´t know if post1 is a post or page. How shall it then redirect on this base?
If you would change the URL structure for pages alone (I don´t think this is possible by default, or am I wrong?) you could target their URL scheme and redirect.
To access the old pages (with the new URL) you could then use a "broken link checker" plugin.
Update: You could possibly use the hook described here to check wether the called post is a post or page and then use wp_redirect to call your new URL.

Wordpress Job Manager Pagination Issue

I am using the Wordpress Jobs Manager plugin. It all works great except the pagination feature. When enabled, the pagination buttons just redirect the user to the homepage instead of to the paginated page of results. As far as i can tell this is a problem with permalinks but i wondered if anyone had a workaround as i cannot use the standard permalinks on my site.
Does anyone know of any possible fixes? Its a custom built theme.
Thanks for you help guys
I know its a long time since you posted, but i had this issue today and came across your post.
I did some investigating and found it to be a problem with the way wordpress was dealing with the rewrites for canonical redirects.
I did a search on the internet and found the following post on wordpress.stackexchange.com by Celine Garel which deals with this situation for custom post types, i just changed it to work with a page.
https://wordpress.stackexchange.com/questions/134339/pagination-on-custom-post-type-not-working-if-permalinks-set-to-rewrite-url
Add this to your themes function file,
add_filter( 'redirect_canonical','custom_disable_redirect_canonical' );
function custom_disable_redirect_canonical( $redirect_url ){
if ( is_page('Your_job_list_page') ) $redirect_url = false;
return $redirect_url;
}
This fixed it for me. Hope it helps you or anybody else.

Rewrited url for page just points to index

The problem I am facing is as follow:
I created a new page in Wordpress with a url rewrite '/foo/'. Probably I hit something
(just configured things in the Admin panel not in the database!) an now /foo/ just points to my index and doesn't point to the given page (anymore!). If I just change '/foo/' to something like this '/foo-1/' it works perfectly.
I think it's to hard figure it out what goes wrong but maybe someone has a good suggestion or knows which data I need to remove from the database!
Thanks in advance,
Nick
Whenever you are fiddling with URL rewrites ( especially with new custom_post_types and taxonomies, but basically everywhere ) it is very important not to forget flush_rewrite_rules(); which basically take care of flushing the WP rewrite rules ( like it's name ) - thus allowing you to declare new ones without a conflict.

Duplicated permalinks on a wordpress page

First I have www.mywebsite.com/blog/ Which is another wordpress Blog under www.mywebsite.com.
Then I created a page inside www.mywebsite.com which has a url of www.mywebsite.com/blog/.
I want to change the first www.mywebsite.com/blog into www.mywebsite.com/blog2 so It won't confuse me anymore.
After changing the permalinks in the admin panel. I can't access www.mywebsite.com/blog anymore.
Is there any way to access the page of the original www.mywebsite.com/blog2/wp-admin? and view the duplicated page www.mywebsite.com/blog/?
Please comments if my question confuses you.
Thanks.
When moving your site, give the guide to moving wordpress or, in this case better, the guide of changing the wordpress url a glance.
Suppose you changed the URIs where you cannot move the files, but still can access the login page (through a redirection or something) you can recover your installation easily.
wp-login.php can be used to (re-)set the URIs. Find this line:
require( dirname(__FILE__) . '/wp-load.php' );
and insert the following lines below:
//FIXME: do comment/remove these hack lines. (once the database is updated)
update_option('siteurl', 'http://your.domain.name/the/path' );
update_option('home', 'http://your.domain.name/the/path' );
run it (once) and you are done. Test your site to make sure that it works right. If the change involves a new address for your blog, make sure you let people know the new address, and consider adding some redirection instructions in your .htaccess file to guide visitors to the new location. Delete those lines from your wp-login.php.

How do I prevent Wordpress from stripping the "at" sign (#) from the URL query string?

I am trying to pass an email address to a wordpress page like so:
http://www.website.com/?email=fakeemail#yeahwho.com
However, Wordpress turns it into this:
http://www.website.com/?email=fakeemailyeahwho.com
I even try URL encoding it like so:
http://www.website.com/?email=fakeemail%40yeahwho.com
But Wordpress is too smart and still removes the %40.
I understand that # is a reserved character, but I should be able to still use the URL encoded version. Alas, Wordpress does not want it to be so.
How can I force Wordpress to respect the # sign? I'm guessing I'll either have to hack the internals, or do some mod_rewrite magic.
from http://www.webopius.com/content/137/using-custom-url-parameters-in-wordpress
First, add this to your theme's functions.php file (or make a custom plugin to do it):
add_filter('query_vars', 'parameter_queryvars' );
function parameter_queryvars( $qvars )
{
$qvars[] = 'email';
return $qvars;
}
Next, try passing ?email=fakeemail-AT-yeahwho.com in the URL and then converting it back with something like this:
global $wp_query;
if (isset($wp_query->query_vars['email']))
{
$getemail = str_replace( '-AT-', '#', $wp_query->query_vars['email']);
}
// now use $getemail
This would only not work in the very rare occurrence of an email that actually has "-at-" in it. You could replace for an even more obscure string like '-AT6574892654738-' if you are concerned about this.
Whatever your final solution, don't hack the core to get it to work. :)
I was having a similar problem and I was able to isolate the issue to an SEO plugin. I'm sure the plugin added a filter to the functions.php but as the plugin wasn't being used uninstalling the plugin also resolved the issue.
I also had this problem, but it wasn't caused by a plugin. It was a result of the 301 redirect that WordPress does with regard to your Site URL having, or not having, a www. in it.
If my Site URL was defined as http://www.mydomain.com, then this would work as expected: http://www.mydomain.com/?email=user#domain.com
If the user came to the site as: http://mydomain.com/?email=user#domain.com (NOTE: no www), then WordPress would redirect to this: http://www.mydomain.com/?email=userdomain.com (NOTE: the stripped # symbol)
My solution was to hard code the www redirect in the htaccess file, so WordPress would never have the opportunity to mess with my URL. This page gives example htaccess lines to redirect non www to www and vice versa: http://dense13.com/blog/2008/02/27/redirecting-non-www-to-www-with-htaccess/
I was having a similar problem today when trying to pass Mailchimp data through to a Gravity Form in Wordpress. I found a solution. The original question stated that Wordpress was also stripping %40, but it didn't for me in this instance.
1) In Mailchimp create a new Merge tag. I called mine 'Email Param' and * |EMAIL2| *
2) Export your list of subscribers
3) Copy the normal 'email' column content into the new 'Email Param' column.
4) Do a Find and Replace for all # symbols to %40
5) Import your list and tick the box that Auto-updates that list
6) Update your URL to include the new parameter
* |EMAIL2| *
That worked for me.

Resources