htaccess rewrite incoming links to new one - wordpress

I'm having a problem with site migration and old links. Now, its not just a server migration, it was also a CMS migration. Site went from umbraco (asp.net) to wordpress. Problem is that google indexed old URLs. We have a way to rework links to make them work. I've been using this method to rework links and used WP plugin for redirect. The problem is there is way to many links for this plugin.
I was wondering is there any way to rework links dynamically with htaccess.
So, here is how links should be rewritten:
http://example.com/something/XXXXX-some-text.html
-->
http://example.com/something/some-text-XXXXX
where XXXXX is some number between 100 and 100,000
This method works, only problem is that there is more then 60,000 links...
Any suggestions?
P.S.
There are also some other links that should be skipped, cause we don't have a way to rework them...

Is this what your want?
RewriteEngine on
RewriteBase /
RewriteRule ([a-zA-Z\-]+)/([0-9]+)-([a-zA-Z0-9\-]+)\.html /$1/$3-$2 [L,R=301]
Put this at the top of your .htaccess file in Wordpress installation.
( ): will capture a string
$#: will print the captured string in the redirection
$1: will print the first captured string
$2: will print the second one
$3: will print the third one
You can use this tool to test that kind of simple rules.

Related

Custom URLs using .htaccess - WordPress

I've tried for ages to find a solution to this but to no avail.
In a nutshell...
I have a WordPress site within which I have a few pages that I want to change the URLs for. I don't want them to be custom post types if it can be avoided, I wish to use my theme's standard page templates without having to change or add any.
Can this be achieved simply using .htaccess? All my attempts have resulted in 404s so far. I've seen in the codex that you can do similar but not 100% sure how this works with pages instead of posts.
Note that I don't want a redirect, just to change the URL.
Example:
domain.com/page-reviews
I wish to be...
domain.com/page/reviews
The rule will always be the same, effectively anywhere that 'page-' appears, I need the dash to be replaced with a slash - 'page/'
Thanks to anyone who can help!
You can't do it through any .htaccess modification, if you are going to rewrite your slugs externally from Wordpress you will end up having 404 errors (or 500 or even a redirect loop, in the worst case scenario). Wordpress will look through its entire database searching for the matching requested path, which obviously would be inexistant.
If you want your pages to sit under a section, let's say /page/ you can easily create a Page with the slug page and then a child page with the slug reviews, so your final page will show the /page/reviews page, you need however to edit each page to amend the slugs where necessary.
If you are, however, using Posts then just use the Custom Permalinks plugin, it allows you to rewrite and add slashes into the full slug in the edit post screen, also in this case you need to go through all posts and change the slug pattern.
We've been using it flawlessly for about the last 2 years in a blog of a big corporate, however keep in mind the author is not maintaining it anymore so it might break at some point in the future and probably you might need to readapt it.

How do I move a Wordpress page up a directory level?

Part of our website is Wordpress. We have had a text blog page at ourdomain.com/blog/ for a long time. We have added a separate videos only page at ourdomain.com/blog/videos/ Now that the videos page is finished they want to move it to ourdomain.com/videos (the text blog would stay in the same place.) How do I change this?
use rewrite rules.
e.g.
RewriteRule ^videos/(.*)$ /blog/videos/$1 [L]
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

Wordpress - Page Aliasing

I don't know why I am having difficulties finding an answer for this, but I was. I am hoping it's quick and painless.
This is my first attempt at a WordPress site. I created a number of pages which reside in a standard navigation. Currently the nav links look like such:
?page_id=2
I want link to be friendly such as:
/restaurant/
I went into the permalinks and tried messing around with the options and I got the URLs to change but on click I get a 404. What am I doing wrong?
two things i could think of
Wordpress can't write the .htaccess file (a warning should be displayed on the permalink page). In that case update it by hand with code shown on the site.
mod_rewrite is disabled on your server http://httpd.apache.org/docs/current/mod/mod_rewrite.html

How to add second permalink to page?

I have a page with a URL like
http://www.example.com/subcategory/therealthing.
This URL should stay like this but I need to create a shortcut that looks like
http://www.example.com/realthing
That shortcut should take the user to the site with the longer URL
A method that is SEO friendly would be perfect.
What's the easiest way if I don't want to change the permalink of the original site? I guess htaccess won't work for this?
Funny, I just answered something very similar to this. See the redirection plugin. Much easier than editing your .htaccess file yourself. Particularly if you need to do it a lot.
Take a look at the feature list for the redirection plugin. This allows you to setup redirects to other pages or do pass through redirections.
If you are happy with redirects .. then you can add this kind of rule into your htaccess file (but it has to be placed before WordPress rules -- if not sure/does not work -- provide your current whole .htaccess):
RewriteRule ^realthing$ /subcategory/therealthing [R=301,L]
or you can try
RedirectMatch 301 ^/realthing$ /subcategory/therealthing
Redirection is not a more reliable solution. You should use this plugin in which you can customize every permalink without any problem https://wordpress.org/plugins/custom-permalinks/

Redirect RegEx interferes with WordPress pagination

I converted a Drupal site to WordPress and am using the Redirection plugin to redirect the old page hierarchy to the new one.
I need to get example.com/page/slug to go to example.com/slug. I used /page/(.*), but that breaks the pagination in WordPress since it uses /category/category-name/page/2 for it's hierarchy. I get urls like example.com/category/category-name/2 instead.
What's the RegEx I need to get both the pagination and the URL redirects to work correctly?
Assuming mod_rewrite syntax, anchor your regex:
^page/(.*)
... this way the category/category-name/page/2 would not match anymore.
NB: to my knowledge a leading slash is not necessary when matching URIs with mod_rewrite.

Resources