Force SSL on WordPress archives - wordpress

I'm using the WordPress HTTPS (SSL) plugin to run my website over https, and have updated my 'WordPress Address' and 'Site Address' fields under the 'settings' menu to reflect that.
All pages and posts run over a secure connection, but archives (which I make substantial use of due to custom post types) don't. Other more traditional archive types such as tag archives act similarly.
As these are sort of pseudo pages (and don't have a physical location to tweak settings in the WP admin), is there any way of forcing these to run over SSL? Is there a trick I've missed editing .htaccess?
Many thanks in advance

You don't really need to use that plugin. And, there are several other things that should be checked to fix the archives and Custom Post Types lack of SSL.
Deactivate the plugin, clear your caches, and then change http to https in the two URL settings in WordPress Dashboard>>Settings>>General and save.
And then force SSL and www for non-SSL incoming traffic by putting these rewrite rules above the WordPress rewrite block in .htaccess:
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
That will take care of all WordPress URLs, and should take care of the Custom Post Types, too.
But check your CPT functions in functions.php or other theme files for absolute http URLs and remove the http: and leaving the //, i.e.
//fonts.googleapis.com/css?family=OpenSans
and not like
http://fonts.googleapis.com/css?family=OpenSans
Check your theme's style sheets for absolute URLs that are httpthe same way, and header links, too, i.e.:
<link href='//fonts.googleapis.com/css?family=OpenSans' rel='stylesheet' type='text/css'>
And, it's a good idea to search all your post/page content to change all http links to https for images and internal links. Changing the WordPress site URL settings to https is not enough, as that does not retroactively change all links in post/page content. Use a plugin called Search RegEx to find/replace links in post/page content. Or, use an SQL find/replace utility called interconnectit.com WordPress Serialized PHP Search Replace Tool to scan the whole database.
Lastly, use the developer tools in Firefox (or Firebug) or Chrome or Safari or IE to check for insecure element errors that are caused by images, scripts, etc., that are not loading over SSL.

Related

how to rewrite non exist url to display content of dynamic page from wordpress

in wordpress normally if click domain.com/index.php?p=2
it redirect to domain.com/sample-page/
say now i like to show sample-page content domain.com/sample-page/
from non exist url
domain.com/member/abc/
domain.com/member/bbb/
domain.com/member/ccc/
but when user run any of above URL example.com/member/xxx/ in browser it will show content of example.com/sample-page/
without any redirection to example.com/sample-page/
so the address still remain in example.com/member/xxx/
please advice how to do in .htaccess or in functions.php
This sounds pretty straight forward, all you need is a single internal rewrite rule:
RewriteEngine on
RewriteRule ^/?member/.+/?$ /sample-page/ [END]
Such rule has to be implemented to be applied prior to the wordpress internal rules.

Remove Old Permalinks?

I have a Wordpress website. I have changed my permalinks several times. All past versions of the permalinks I used are still working. If I type them into the URL bar, I am taken to the page WITHOUT the URL changing/redirecting to the new/current permalink.
Why aren't the old permalinks redirecting to the new one?
This is causing issues with Google reading duplicate content.
Example: .com/lightbulb .com/shop/lightbulb
The second URL is old, but still works when I type it in.
Shouldn't it redirect to the new one?
How can I remove old permalinks from being found by Google?.
Thanks in advance
I think the old permalinks is stored in the table postmeta with the meta_key of _wp_old_slug
If you wanted to clear all of the old slugs you could use this:
DELETE FROM wp_postmeta WHERE meta_key = '_wp_old_slug';
As you can see, Wordpress doesn't handle redirections when you change your permalinks structure. There is 2 ways to handle this, through:
The htaccess rewriting rules (manually editing the .htaccess file) depending on your new old/new permalinks structure. If .com/lightbulb is the new path and .com/shop/lightbul the old one:
Options -Indexes
Options -Multiviews
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RedirectMatch 301 /shop/lightbulb(.*) /lightbulb$1
# or
# RewriteRule ^shop/lightbulb?(.*) http://www.domain.com/lightbulb$1 [R=301,L]
</IfModule>
But if you want to redirect old permalink structure .com/shop/ to main domain your .htaccess rules will be:
Options -Indexes
Options -Multiviews
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RedirectMatch 301 /shop/(.*) /$1
# or
# RewriteRule ^shop/?(.*) http://www.domain.com/$1
</IfModule>
Permanent redirection is used for best SEO practices, redirecting definitively old permalinks to new ones, avoiding duplicate content, and telling search engines that your old permalinks have been moved definitively to new ones.
Redirection Wordpress free plugins (there is a lot):
Redirections plugin is the most popular and offer a easy-to-manage 301 redirections and 404 error tracking. It also offers more advanced tools to help you keep track of loose ends on your site like broken links and orphan pages.
Simple 301 redirects plugin is simple and deals with 301 redirect creation for when you’ve permanently moved content from one location to another.
Quick Page/Post Redirect plugin easily redirect pages/posts or custom post types to another page/post or external URL by specifying the redirect URL and type (301, 302, 307, meta).
Safe Redirect Manager plugin comes with an additional whitelist feature for added security…
SEO Redirection Plugin plugin offers support for generating 301, 302, and 307 redirects and also supports 404 error monitoring with easy one-click redirection…
Converting old path (urls) in database (if they still exist):
You can use Search and Replace free plugin, to easily find some old related urls or path in your database and bulk replace them by the new ones. This is a very powerful plugin, a little buggy, but working fine when you know it (but make always a backup before).
A recent reference:
A Simple Guide to Changing Your Permalinks Without Breaking Your WordPress Website
Why aren't the old permalinks redirecting to the new one?
Each time you add new permalink structure and flush rewrite rules, WordPress doesn't redirect old links to new links. Instead, WordPress will alter the old links with the new links completely.
All past versions of the permalinks I used are still working.
In WordPress, a URL doesn't map to route. It's looped through rewrite rules to find a match - a real URL which can be translated into database queries by parse_request method.
It means that if the old rewrite rules which match old links aren't removed. The old links still work.
How can I remove old permalinks from being found by Google?
Since they have been indexed by Google, I think permanent redirects is the best solution.
I assume you're using Apache, if not, please let me know.
In your case, just add following code before WordPress rules in your .htaccess file:
RewriteEngine On
RewriteRule "^shop/(.+)/?$" "http://example.com/$1" [R=301,L]

How to rewrite https to http for a specific url?

I'm seeking help with an issue, basically my entire ecommerce website runs on HTTPS with wordpress but I have recently become affiliated with ebay.
However when I try to display their products on my site using a HTTPS page none of the images show and I get this error:
Failed to load resource: net::ERR_INSECURE_RESPONS https://thumbs2.ebaystatic.com/m/mPA8yaCHEhocIoW2TdC-0hQ/140.jpg
I'm trying to change (https example.com/shop/ebay-shop/) to (http example.com/shop/ebay-shop/)
so that the images are displayed correctly. Unless anyone knows how I can make the images load without having to redirect to http?
Thanks.
Try adding this to the top of the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^shop/ebay-shop/ http://example.com%{REQUEST_URI}
Note, you'll need to be careful with any wordpress plugins or settings that will attempt to re-redirect such a request back to https. If that happens, you'll end up with a redirect loop.

Wordpress. Rewrite url when on custom taxonomy

It's a wordpress site. I am using a plugin called media tags. This plugin create a custom taxonomy called 'media tags' to display media that has been tagged. The url for these pages are currently domain/blog/media-tags/results
I would like to remove the blog part only when on a media-tags page. So I end up with:
domain.com/media-tags/results
but the standard blog posts,categories & tags still keep the blog part of the url:
domain.com/blog/cat/post-title, domain.com/blog/cat, domain.com/tag/post-tag
Is this possible please?
I'm assuming you just need a snippet for your .htaccess file.
RewriteEngine on
# condition to avoid recursion:
RewriteCond %{REQUEST_FILENAME} !blog
# your rewrite rule:
RewriteRule media-tags blog/media-tags
When the server receives a request to domain.com/media-tags/results it will rewrite the target URL as domain.com/blog/media-tags/results.
I guess you will also have to configure your plugin to point the URLs to the root directory of your server. From the Media Tags plugin homepage:
You can also change this ‘/media-tags/’ URL parameter to something of your liking like ‘/gallery/’. To do this log into wp-admin and go to the Permalinks page under Settings. At the bottom of the page you will see the input field for Media-Tag. Simply enter your preference and update the page.

How to internally add /blog/ to the url with .htaccess?

Hi I have wordpress installation in subfolder /blog/, as it has to co-exist with other legacy cms, so now if i wish to access some page of wordpress i need to use links as
www.domain.com/blog/news/ and would like to rather use www.domain.com/news/.
So basically for certain links i need to add this /blog/ somehow internally so wordpress
would handle it normally.
Please note it will be few links so rewrite rules can be literal.
Rewriting URI's for wordpress can always be kind of sketchy because wordpress has its own way to do routing and may not play nicely with other rewriting sometimes, but you can try:
RewriteRule ^/?news/some-page$ /blog/news/some-page [L]
As long as they're before any other wordpress related rules.

Resources