mod_rewrite caused drop my ranking - .htaccess

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]

Related

How to make 301 redirect from one website to another where the ending is different?

I have 2 websites:
OLD one - https://www.old.example/en/
NEW one - https://new.example/en
Lastly, Google Search Console reported around 80 improperly redirected links for OLD website, i.e.:
https://www.old.example/en/?p=41310
https://www.old.example/en/?p=45659
https://www.old.example/en/?p=72785
In .htaccess of OLD page is inputted only code:
Redirect 301 / https://new.example/
which redirects above links from OLD page to i.e.
https://new.example/en/?p=62692
How can I correct it and i.e. expect to have in such cases always redirection to main page - https://new.example/en
To remove the query string completely (without a stray ? at the end) you'll need to use mod_rewrite instead.
For example, in the .htaccess at the old domain:
RewriteEngine On
RewriteRule ^(en)/ https://new.example/$1 [QSD,R=301,L]
Aside: Although this many-to-one redirect will likely be seen as a soft-404 by Google.

.htaccess - fixing duplicate content issues

Some pages are showing up as duplicate content when I run a page crawl with seoMOZ.
for example:
/index.php
and
/index.php/
are being crawled as two separate pages. How I would implement a mod-rewrite to remove trailing slashes from only .php files?
Also
mysite.com/dir/
and
mysite.com/dir/index.php
are being flagged as duplicate content. I would prefer to have all "/dir/file.php" links redirected to "/dir/" for aesthetic reasons, but I'm not sure of how to do this or if it is the best thing to do from an SEO standpoint.
Thanks for help and advice.
An couple ideas:
Add a rel="canonical" link to the section of the non-canonical version of each HTML page.
Taken from http://support.google.com/webmasters/bin/answer.py?hl=en&answer=139394
This means that you can set only one page to be the "orginal" or "authoritative" page to be indexed instead of the pages that contain the same content. This is great for pages that show posts by tags, for example.
ALSO
You can do a redirect. Crack open you htaccess and redirect all inquiries with a query string.
RewriteCond %{QUERY_STRING} .
RewriteRule (.*) $1?
There are a lot of ways to handle this, however.

HTACCESS RewriteRule changes URL OK but gives 404 page

I'm building a new site using Joomla and I've selected 'Search Engine Friendly URLs' and 'Use URL rewriting' in the Global Configuration which gives good SEF URLs but not quite perfect!
If a link to a page doesn't have a menu item associated to it the URL would look like this:
example.com/10-category/5-article
I want to remove the numbers and the hyphen using htaccess so it looks like:
example.com/category/article
I've made Rewrite Rule's in my htaccess file that looks like this:
RewriteRule ^([0-9]+)-(.*)/([0-9]+)-(.*)$ /$1$2/$3$4 [R=301,L]
RewriteRule ^([0-9]+)(.*)/([0-9]+)(.*)$ /$2/$4 [R=301,L]
The browsers address bar now shows the URL I want, example.com/category/article but the page shows a 404 error!
Is it something to do with the Joomla SEF?
What am I doing wrong?
*Update*
The first RewriteRule which removes the hyphen only works OK by itself, I only receive the 404 error page when both RewriteRule's are active.
This is a blind guess, Joomla probably needs those numbers to know which content to serve. It cannot just tell by the name of the category or article (in fact in most of these cases you can even leave it out), but it's the number that's important.
So when you're rewriting the URL without the numbers, you're requesting pages that Joomla has no idea how to handle, and it'll give you a 404. The only solution would be to write a plugin or something that maps the names of categories and articles to the corresponding IDs, but that's not going to be easy.
Concerning SEO, I don't think the number in the url is that much of a negative effect. If the rest of your website's SEO is good then this won't matter.

Effective Mass URL Forwarding

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>

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.

Resources