Best way to set up a redirect? - wordpress

I'm using wordpress. I have a post that has a pretty awkward url, like:
http://example.com/dogfood/why-do-dogs-like-bacon-i-will-investigate
I want to change the url to something more succinct, in hopes that it would improve my search results ranking:
http://example.com/dogfood/dogs-and-bacon
But this article is pretty popular now, and many third party sites have links pointing to the original url.
Is the best solution here to:
Duplicate the same post content at the new url.
Leave the old post as-is (the url will remain intact).
Set up a 301 redirect in my .htaccess file from the old url to the new url.
This way links to my old article will still work, but (hopefully) new searches for dog food bacon will start ranking my new url higher? Or can I simply delete the old post after I setup the redirect in my .htaccess file - no need to keep the old url around actually?
Thanks

Here are my thoughts:
Duplicate content is almost always a bad idea.
I think that leaving the old post URL intact is just fine. There's really no reason to change it. If what you want is to generate more traffic, there are other, more "kosher" ways of doing so: get other sites to link to your article or write an update to the article in a new post and add a link to the current article. Besides, I think people are more likely to search for "Why do dogs like bacon?" than "dogs and bacon".
Technically a 301 redirect in your .htaccess file would be the best solution if you insist on changing the URL (which I discourage), but it would be a b*** to maintain for every post you want to redirect. Consider using a plugin that will do this for you, like Redirection.

Related

Using Slashes In Url’s?

This is my first time using Ghost, and I installed the latest version for the first time yesterday.
I have a site which has links like:
site.com/2010/03/03/post-name
I tried to manually edit the URL when posting them, but it changed it to:
site.com/2010-03-03-post-name
I tried to look around and I found out that you can use /year/month/date on the URL, but that impacts all URLs. Not all of my old URL’s are on that format, but there are some of them which are very important in this case.
So my question is:
Is it possible to change the URL structure of SOME posts with the date, and some with default format?
I am tired of searching, and if I can’t find a way, I am just going to redirect the old URLs to the new ones.
Thank you in advance!
Do those posts need to live on those URLs? You can use custom collections to rewrite some posts depending on the tag they have applied, however I think it would be better if you went down the alternative route and redirecting those URLs to newer and more consistent ones. Ghost has a built in redirects feature which you can read up on here:
https://ghost.org/docs/api/v3/handlebars-themes/routing/redirects/

How do I point a vanity URL to my homepage without the URL changing in the browser?

I'm trying to make a vanity URL, say example.com/saveWD, take someone to the homepage, example.com, but not actually redirect it - so they see example.com but the URL in their browser reads example.com/saveWD. Right now I have this in my htaccess file:
RewriteEngine On
RewriteRule ^saveWD index.php
Is the best way to go about creating this? If so, what am I doing wrong?
Thank you!!
I wonder why you'd need to do something like this, but I've had to do much crazier things haha.
You can absolutely use .htaccess rules, which if you only need a few vanity URLs will be absolutely sufficient, or set up domain masking (which would probably be way over-complicated for this).
Shameless plug, I've also written a plugin that may work for what you need called Content Mask. You make a page/post and put a URL in the Content Mask URL field, and it will replace the content of that page/post with the content from the URL.
I wrote it because we needed to embed external landing pages and reputation software, such as example-client.reputationsoftware.com or landingpagemaker.com/example-client/landing-page-1 onto https://example.com/reviews or https://example.com/landing-page.
I made a test using my plugin's homepage https://xhynk.com/content-mask/ and masking it on https://xhynk.com/content-mask/saveWD
You're more than welcome to give it a shot if you want, here's the source code of the current version so you can see nothing funky is going on: http://plugins.svn.wordpress.org/content-mask/tags/1.2.0.2/content-mask.php

Regex 301 redirects

Using Wordpress/Woocommerce latest versions:
I need to 301 redirect my old shop urls to my new site that has cleaner urls, but with over 2000 urls, I am looking automate this, as much as possible. Hopefully a regex pattern in the .htaccess can do this? I have very limited knowledge of how to do this, so any help would be much appreciated.
OLD URL FORMAT
foobar.com/vintage-industrial/3135-sgabello-alto-cindy-industrial-arredamento-industrial-sgabello-.html
foobar.com/shabby-e-provenzale/3270-cubo-cottage-2-cassetti-arredamento-shabby-chic-etnico-nordico.html
foobar.com/mobili-etnici/3286-armadio-lambert-blue-arredamento-etnico-classico.html
foobar.com/mobili-etnici/3335-tavolo-telgede-80-tavolo-rustico-industrial-arredamento-etnico-arredamento-industrial.html
foobar.com/sedie-sgabelli/1687-sedia-jenny-arancio-sedie-colorate-pop-vintage.html
the above example shows a directory, which can be anything, followed by the product id and name
NEW URL FORMAT
foobar.com/prodotto/sgabello-alto-cindy
foobar.com/prodotto/cubo-cottage-2
foobar.com/prodotto/armadio-lambert-blue
foobar.com/prodotto/tavolo-telgede-80-tavolo
foobar.com/prodotto/sedia-jenny-arancio
every new url will be in this simple format & all will have the 'prodotto' base url
The old url's have a lot of keywords stuffed into them, which have been removed from the new url's
UPDATE
Is there a way I can strip out this part of the old url's:
'vintage-industrial/3135-'
I think this is all I may need to do, as mod_rewrite should find the product from the remaining part of the url? So i would be left with
foobar.com/sgabello-alto-cindy-industrial-arredamento-industrial-sgabello
Thanks
So basically we have:
foobar.com/type/####-product-name-and-key-words.html
that will be translated into
foobar.com/prodotto/product-name
If you only have a few of the types we can do something like this:
RewriteRule "^/first-type/[0-9]+-(.*)\.html$" "/prodotto/$1"
RewriteRule "^/second-type/[0-9]+-(.*)\.html$" "/prodotto/$1"\
Which is safer, but somewhat tedious if you have a lot. We could also do this:
RewriteRule "^/.*/[0-9]+-(.*)\.html$" "/prodotto/$1"
Which is faster, but has a slight risk of matching things we don't want. Either way we will be left with foobar.com/prodotto/product-name-and-key-words
I think this is all I may need to do, as mod_rewrite should find the product from the remaining part of the url?
If it does then that's great! We're done. If not, we'll have to continue.
If you don't have an easy to follow rule for separating name from keywords, then we'll have to get a little more creative. We can override WP's 404 page with our own code. This 404 page will do something very strange. It will strip the last section of its url off (based on dashes/slashes) and redirect to the cut down url. This way we will progressively approach the right page:
foobar.com/type/####-product-name-and-key-words.html
foobar.com/prodotto/product-name-and-key-words
foobar.com/prodotto/product-name-and-key
foobar.com/prodotto/product-name-and
foobar.com/prodotto/product-name
This has the negative affects of having a lot of redirects, but being permanent their browser should learn. It also means you effectively can't have a 404 page, as it will progressively strip the url down till you reach your home page.

Lost all my sharing stats by purchasing a domain

I lost all the likes on my website on Wordpress then I bought the domain. It turns out that is the same site, but now no longer use the wordpress.com but .com (http://sobreasdeliciasdavida.com/).
Despite recent, my blog already had good statistics and the loss of more than 500 shares in Facebook brings my blog back to its beginning.
Can you offer the option of importing the likes to the new domain since the posts are the same?
Is there any way to do this?
Oftentimes when you move a well-established site, you'll want to set up a 301 redirect from the previous site. It's a permanent redirect that ensures that people following links to your previous site end up at your new one. I should point out, though, that your blog is far from taken back to its beginning. Remember, content is king, and you now have a site that's totally under your control and is already packed with great content, content that you know people respond to, like in social media venues, comment on, etc., etc. Don't worry about the 500 you might not get back because you certainly have thousands more on the way if you just keep doing what you're doing.
If you are directly using the facebook code in your website, then you can check this out. http://searchenginewatch.com/sew/how-to/2172926/maintain-social-shares-site-migration

Using nginx rewrite to hide or clean URLs?

Greetings.
I've been trying to grok regexes and rewrites but i'm a newbie at it. I have a simple site, one dir only, all i want is to rewrite domain.com/file.php?var=value to domain.com, making sure the user will only see domain.com in the adress bar throughout site navigation (even if i start making the site more complex).
Simply speaking it's freezing the url, although if the site grow's i'd rather make some "clean url" approach but i'm still at basic php and i sense i'd have to rtfm on http/1.1
You can use nginx rewrite rule like this:
rewrite ^([^.]*)$ /index.php
to send all requests that do not contain a "." to your index.php script. In your php script, explode the request url to get the passed parameters, and then call the php page you want to:
#URL /people/jack_wilson
$url_vars = explode('/',$_SERVER['request_uri']); # array('','people','jack_wilson');
$page = $url_vars[1];
if($page == 'people'){
$username = $url_vars[2];
require('people.php'); #handle things from here.
}
Typically this type of "clean" URL stuff is typically accomplished with a wrapper frame for the entire site. The browser shows the URL of that frame only, and the contents can be whatever.
But I actually don't recommend it, because the user may want to bookmark the "dirty" URL.
This type of URL obfuscation diminishes usability for advanced users.
Not to be a jerk, but I typically only see this type of URL obfuscation on "artsy" sites that care more about what their address bar looks like than usability of their site. Making your users happy via enhanced usability is a better long term approach IMHO.
I guess freezing the url is driven by marketing desires, so here's the downside to that, from marketing standpoint as well: your users won't be able to send a link to a page they liked to their friends via IM, email or facebook, so it actually decreases the appeal of your site even for the most clueless users.
I don't (knowledgeably) think it's safe to have php variables showing around in the adress bar (although they'd show in the status bar of some browsers anyway...). Idealy the user wouldn't know what is the site using behind the scenes - i'm configuring error pages for starters. And yes, for aesthetics as well. If i can rewrite to domain.com/foo/bar i'd be happy; assuming nginx would handle the "translation back to ugly URLs" if it got such a request, which i think it does with location-directives. But having domain.com/file.php?var1=value&var2=value kinda annoys me, makes me feel i'm exposing the site too much.
Frames are not recomended (especially 'cos of search engines) and i'm trying to stick to xhtml 1.1 Strict (so far so good). If the content is well designed, easy to navigate, acessible regardless of browser-choice, intuitive, etc... i guess i could live with cute URLs :)
I'd gladly grok through any rtfm material regarding good webdesign techniques, php, http/1.1 and whatever made you go "Yeah! that's what i've been looking for!" at 4am.
Thanks :)
[if i understand this site right, this oughta be a reply to the original post, not to an answer... sorry]
You could also look into a PHP framework such as Code Igniter that will handle all the PHP side of this for you.
http://codeigniter.com/

Resources