Effective Mass URL Forwarding - .htaccess

I'm doing the migration of a site, from MovableType to WordPress. The website contain around 3500 posts and when I uploaded the information to the new version of the site, the links have been altered.
Old site link (note that the category-name and the nodenumber are not fixed values. The nodenumber is a number that change in each post):
http://websitename.com/category-name/nodenumber/title-of-the-post
New site link: http://websitename.com/category-name/title-of-the-post
My question is the following:
What would be the easiest and effective way to configure my Htaccess file to do a redirection from the old links to the new ones? There might be a simple way than to write them all by hand.

If the structure of the URLs is always like this, and the second part is always a number, the following should work in your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.+)/[0-9]+/(.+) /$1/$2 [L]
</IfModule>

Related

htaccess URL overwrite - Magento

I have some URLs that I would need to overwrite so that if someone looks at the source code they can't actually see the real URLs for the product images in Magento. Currently, the link is as
externalsub.domain.com/images/image123.jpg
I want to make it as
mydomain.com/images/image123.jpg
How can I achieve this via .htaccess? Any help is much appreciated!
Then in an htaccess file, you can use this (above whatever rules you may already have):
RewriteEngine On
RewriteRule ^images/([^/]+\.(?:jpe?g|png|gif))$ http://externalsub.domain.com/images/$1 [L,P]
You don't need the line turning on the rewrite engine if you already have that (only needs to be in your file once).

.htaccess to change the url path

I have tried several examples of solutions that I have found here on StackOverflow but none of them seem to work correctly.
I have a Magento store that I need to redirect an old store code url to the new one. For example:
The old url looked like this.
www.example.com/something_en
In the above example I need to be able to modify any url that contains to the path something_en and change it to something like in the next example.
www.example.com/something
Any help is much appreciated.
Make sure this is your very first rule in main .htaccess:
RewriteEngine On
RewriteRule ^something_en(/.*)?$ /something$1 [L,NC,R=301]

How to redirect a folder and its pages to a single page

I'm trying to redirect some files and I'm pretty stuck. There are way too many to do some of them on a "page-per-page" basis and so I need a quick way as these pages are insignificant but return 404's at the moment.
I have a page like this "/old-blog/tag/page", I previously redirected the "old-blog" to "new-blog" so I get "/new-blog/tag/page" but now I want "tag" and all pages after this to be sent to "new-blog". I hope this example makes sense, please ask if I've missed something.
I'm doing my redirects with my .htaccess file so I'd like a method I can use with this in mind.
Thanks, Dan.
You may already have rewrite rules, if there are rules that do some type of routing, then mod_rewrite and mod_alias is going to conflict (RedirectMatch is mod_alias). So try sticking with just mod_rewrite. Try adding these rules, above any other rules, in the htaccess file in your document root:
RewriteEngine On
RewriteRule ^/?old-blog/tag /new-blog/ [L,R=301]

301 Redirect to change structure

I have been researching redirects for a few days now and am still struggling, so I decided to post my first question here. For some reason, it is just not clicking for me.
I have redesigned and developed a client's WordPress site and need to update it's structure.
The site's current structure is:
www.domain.com/blog/postname/2011/12/26/
The new structure should be:
www.domain.com/blog/postname
I really thought this was going to be easy since all I am looking to do is drop the date, but have not been able to grasp the whole wildcard aspect and how to end what I am trying to match. Any help would be greatly appreciated. A simple answer is great, but an explanation would be even better.
I am assuming you already know how to change your WordPress permalink structure to drop the date.
To 301 redirect all of the old URLs to the new ones, add the following rules to your .htaccess file in the root of your websites domain, ahead of any existing rules that are there.
#if these 2 lines already exist, skip them and add the rest
RewriteEngine on
RewriteBase /
# if there is a request of the form /blog/post-name/yyyy/mm/dd/
RewriteCond %{REQUEST_URI} ^(/blog/[^/]+/)[0-9]{4}/[0-9]{2}/[0-9]{2}/$ [NC]
#redirect the request to the URL without the date
RewriteRule . %1 [L,R=301]
If you want to learn more about .htaccess/rewriting you can take a look at the following urls: Indepth htaccess, Brief Introduction to Rewriting, Apache Mod_rewrite.
Let me know if this works for you and/or you have any issues.

mod_rewrite caused drop my ranking

I'm owner of http://myisfahan.com. I have an article management system there that developed by myself.
Recently I changed article links from myisfahan.com/articles/isfahan_articleXXX.html to myisfahan.com/XXX_[article subject].html in newer version. Many of my articles had high ranking on Google (in Persian language).
Because I didn't know redirect older links to newer one I only wrote 2 instruction only in the .htaccess:
RewriteRule ^([0-9]+)_([^/\.]+).html$ maghalat.php?id=$1
RewriteRule ^articles/isfahan_articles([0-9]+).html$ maghalat.php?id=$1
After this major change Google.com dropped many of my page rankings and recently I have only 20% of normal site visitors.
My questions are:
Does this changes caused this drop of ranking, because in fact now I have 2 links for every content .
I fetch subject text by PHP and generate XXX_[article subject].html, how can I write a rewrite syntax that redirect isfahan_articlesXXX.html to XXX_[article subject].html file when XXX is article's ID in .htaccess file?
You should have 301 redirected your old links to your new links, after creating your new links.
If you did not or are duplicating links to the same content, this would indeed hurt your rankings.
UPDATE
Looks like you already have the RewriteRules in place that you need. Just add the following flags (note the 301 redirect for the old links) and over time it should (over time) rebuild your page rank.
RewriteRule ^([0-9]+)_([^/\.]+).html$ maghalat.php?id=$1 [L]
RewriteRule ^articles/isfahan_articles([0-9]+).html$ maghalat.php?id=$1 [R=301,L]

Resources