On our website using Joomla we have duplicate URLs for the same page being found by Google Webmaster Tools. For instance the following URLs go to the same page on our site:
/lawson-equipment/auxiliary-equipment/poly-pro-sinks?option=com_content&view=article&id=75&Itemid=74
/lawson-equipment/pre-press/poly-pro-sinks/index.php?option=com_content&view=article&id=75&Itemid=74
/technical-support/digital-learning?option=com_content&view=article&id=75&Itemid=74
/lawson-equipment/textile-equipment/dryers/encore-dryer
with the fourth URL being the actual path I want. How would I go about formulating a rewrite rule that would grab any URL query strings with "&id=75" to be directed to the SEF URL without doing a Redirect 301 for each of the incorect URLs? This happens often.
Success! Using a RewriteCond command with a common snippet from the non-SEF addresses, and a RewriteRule command for the target address using regular expressions I come up with the following for my .htaccess file:
RewriteCond %{QUERY_STRING} ^.*com_content&view=article&id=75&Itemid=74$
RewriteRule ^index\.php$ http\:\/\/www\.mysite\.com\/lawson\-equipment\/textile\-equipment\/dryers\/encore\-dryer? [R=301,L]
So far this seems to be working and hasn't affected anything else that I can see. Please feel free to comment or add another answer if there is a better way of doing this!
Related
Summary:
I've been asked to migrate a .asp site over to Wordpress, but I'm having some issues with the .htaccess redirects.
What I'm trying to Achieve:
Pages:
domain.com/Some-Page-On-My-Site.asp
redirects too
domain.com/some-page-on-my-site/
Posts:
domain.com/articles.asp?title=The-Greatest-Post-Title
redirects too
domain.com/blog/the-greatest-post-title/
End Goal
Stay consistent with default Wordpress permalink structure using lowercase.
Convert only the .asp URL requests to lowercase not the rest of the site.
I'm thinking that because of the *.asp pages redirect that it may be sucking in the articles.asp and converting it to /articles/ . So I swapped their spot in the .htaccess file.
I'm thinking that RewriteCond and Skip Flag is probably required for this to work. But could be wrong.
I'm glad I was able to get the Pages redirect to work, although I think there is just a little more to make these work better.
What I've tried
This converts URL Requests for old .asp pages to new URL Structure:
RewriteRule ^(.*)\.asp$ /$1/? [L,R=301]
These attempts do not convert URL Requests for old .asp posts:
# Try 1
RewriteRule ^articles\.asp?title=(.+)$ /blog/$1/ [L,R=301]
# Try 2
RewriteRule ^articles\.asp?title=(.*)$ /blog/$1/ [L,R=301]
# Try 3 - Not that this would probably work but was an attempt
RewriteCond %{QUERY_STRING} (^|&)title\=(.+)($|&)
RewriteRule ^articles\.asp$ /blog/$1/? [L,R=301]
I confirmed that I can do 1-to-1 redirects, but not similar to the Pages structure like above where I can type anything before .asp and it just removes the .asp
RewriteCond %{QUERY_STRING} (^|&)title\=Duck\-Feet\-Wine($|&)
RewriteRule ^articles\.asp$ /blog/duck\-feet\-wine/? [L,R=301]
Does anyone have some insight on this? or am I crazy to think that I can do this?
I've read about 100+ pages and I'm stumped, including stumped on how RewriteCond works. I happy that I was able to get the pages redirect to work, now to convert a query string to a static like link to work with Wordpress's lowercase permalink structure.
I'm new at programming. We have an office project, the website's URL is www.project.com.ph (sample name), this is already a live website from the client. But the released printouts have the instructions for the users to go to www.project.com/ph which is wrong and we can't reprint the material since it already reached plenty of event places.
Now the problem is, we need to redirect to www.project.com.ph automatically if the users type in the browser's address bar www.project.com/ph. I ask if this is possible without any kind of CMS or Wordpress and how to actually do it? We bought a new domain www.project.com for this. Any kind of help is appreciated.
Try the following near the top of your .htaccess file in the root of www.project.com. This works OK (although marginally less efficient) if both domains are pointing to the same place, since it specifically checks that we are requesting the "wrong" domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?project\.com$ [NC]
RewriteRule ^ph/?(.*) http://www.project.com.ph/$1 [NC,R=302,L]
This will redirect requests for www.project.com/ph (no slash), www.project.com/ph/ (with a trailing slash) and www.project.com/ph/<whatever> to http://www.project.com.ph/<whatever>.
This is a temporary (302) redirect. Change it to a permanent (301) only when you are sure it's working OK.
From kj.'s answer on a similar question, here
In your .htaccess for www.project.com, this should do the trick.
RewriteEngine on
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
This will redirect any request to project.com to the domain http://www.project.com.ph/
To include the path after the /ph/` you can use this.
RewriteEngine on
# redirect including path after ph/ (e.g. project.com/ph/directory/file.php to project.com.ph/directory/file.php
RewriteRule ^ph/(.*)$ http://www.project.com.ph/$1 [R=permanent,NC,L]
# redirect any other requests to project.com.ph index
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
You can redirect (301 redirect) the URL using RewritrRule in .htaccess file
RewriteRule "http://www.project.com/ph/(.*)" "http://www.project.com.ph/$1" [L,NC,R=301]
I recently installed Prestashop which has URLs in the form of domain.nl/my-account . Now I added a second language which turns URLS into domain.nl/nl/my-account or domain.nl/en/my-account
As people have bookmarked different items and searchengines have indexed the site I would like to redirect visitors to the old URLS (without the language) to be redirected to the same URL with language (NL is preferred).
A redirect to the mainpage is all I could achieve up to this point. Does anyone have an idea how to set this up using .htaccess??
Any help is greatly appreciated.
Try adding this to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(nl|en)/
RewriteRule ^(.*)$ /nl/$1 [L,R=301]
So you may need to change the (nl|en) part, because that regex checks to see if the URL already starts with /nl/ or /en/. You can replace the "en" with whatever other language you don't want redirected.
I've made a huge mistake in my shop when creating pagination links. After the .html, instead of a question mark my code just appended an ampersand. Now Google Webmaster tools is throwing up hundreds of 404's.
I know how to fix the problem on a URL by URL basis, but is there a wildcard solution as a first off sanity check in HTAccess to check for ".html&" and replace with ".html?"?
Below are examples of my issue, myitemspage represents a category of items, so i have over 50 categories:
http://www.domain.com/myitemspage.html&page=1&limitchange=10
http://www.domain.com/myitemspage.html&page=1&limitchange=25
http://www.domain.com/myitemspage.html&page=1&limitchange=50
http://www.domain.com/myitemspage.html&page=1&limitchange=100
Thank you for any help on my self-created nightmare,
Mark.
Try:
RedirectMatch 301 ^(.*)\.html&(.*)$ /$1.html?$2
or using mod_rewrite:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.html&(.*)$ /$1.html?$2 [L,R=301]
in the htaccess file in your document root.
I am working on wordpress blog and the its has the url pattern something like this. localhost/blog/2012/10/12/sample-post/ .
Now i have updated the url pattern to localhost/blog/sample-post/.
Now i need a redirection to second URL pattern if someone enters the first URL Pattern as i have already submitted URLs with first pattern to couple of articles.
i.e, localhost/blog/2012/10/12/sample-post/ should be redirected to localhost/blog/sample-post/
Can anyone assist me by providing htacess code ?
Try adding these to the htaccess file in your document root. Make sure they are before any wordpress related rules:
RewriteEngine On
RewriteRule ^/?blog/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.*)$ /blog/$1 [L,R=301]