Cscart 301 redirect to Opencart - .htaccess

i am trying to redirect from a Cscart url to a Opencart url but it seems that it does not work.
Old url (cscart)
https://www.example.com/index.php?dispatch=categories.view&category_id=1430
new url (opencart)
https://www.example.com/index.php?route=product/category&path=1746
I want to do this manual for the first 10 main categories and all other subcategories from cscart to redirect to the https://www.example.com home page.
How can i succeed this?
Also, the new url uses https.
Thank you in advance
-Konstantinos

A simple, manual way would be
RewriteCond %{QUERY_STRING} dispatch=categories.view&category_id=1430
RewriteRule ^index.php$ /index.php?route=product/category&path=1746 [R,L]
and so on for all other category mappings.
An alternative could be to capture the old category_id and use it with RewriteMap in the RewriteRule substitution URI
RewriteMap categories txt:/path/to/categories.txt
RewriteCond %{QUERY_STRING} dispatch=categories.view&category_id=(\d+)
RewriteRule ^index.php$ /index.php?route=product/category&path=${categories:%1} [R,L]
And in the file categories.txt, you would have a mapping from old to new category ids
1430 1746
123 456
987 333
See also txt: Plain text maps for more details, or alternatives to plain text mappings.
The drawback of this method, you cannot use it in an .htaccess file, only in the main configuration or virtual host section.
When everything works as it should, you can change R to R=301.

Related

Rewrite URL Structure

I would like to change the URL structure of my site. My current URL structure is like this:
www.domain.com/events/events.php?location=san%20francisco
I want to change the URL structure to:
www.domain.com/events/san-francisco
My XMPL site map has the URLs listed like the first example. I want the search engines to index the URL like the second example. What are all the things I need to do to achieve this? The {city} in the location parameter is dynamic depending on the user's IP address. Do I need to change my XML sitemap to list new URL structure? What do I need to put in my .htaccess file. Do I need to change the actual URLs links on my website to the new structure or can I just use .htaccess?
This should work:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /events\.php\?location=(.*)%20(.*)\ HTTP
RewriteRule ^ /events/%2-%3\? [R=302,L]
RewriteRule ^events/(.*)$ /events.php?location=$1 [L]
Changing R=302 to R=301 when you know it redirect correctly
EDIT:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /(.*)/(.*)\.php\?location=(.*)%20(.*)&lid=(.*)&slid=(.*)\ HTTP
RewriteRule ^ /%3/%4-%5/%6/%7\? [R=302,L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)$ /$1/$1.php?location=$2&lid=$3&slid=$4 [L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /(.*)/(.*)\.php\?location=(.*)%20(.*)\ HTTP
RewriteRule ^ /%3/%4-%5\? [R=302,L]
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+)$ /$1/$1.php?location=$2 [L]
You have to use a .htaccess file similar to the one below. It will match fancy URL and forward the request to the right php file.
RewriteEngine On
RewriteRule ^([^/]*)/(.*)$ /$1/$1.php?location=$2
With this, both www.domain.com/events/events.php?location=san%20francisco and www.domain.com/events/san-francisco will lead to the same page.
But if you don't change your sitemap nor the links on your site, search engines won't know that.
You have then 2 solutions :
change all your links in your site and sitemap with the new structure URL
use a redirect rule to redirect "old" pages to the "new" ones
From what I know about SEO, the first option is the best. Or even better, a combination of both solutions : change all your links, and use a redirect 301 rule so pages already indexed by search engines will not lost their ranking and to avoid duplicate content.
RewriteRule ^([^/]*)/(.*).php?location=(.*)$ http://www.yourdomain.com/$1/$3 [R=301]

Redirect old page to new page use htaccess

I have new Content Management System which rewrite old static code.
I want to redirect some old page to some new page, for example I want to redirect 3 pages only to 3 new pages:
domain.com/oldpage1 => domain.com/new/newpage1
domain.com/oldpage2 => domain.com/new/newpage2
domain.com/oldpage3 => domain.com/new/newpage3
how to do it with .htaccess?
You can use mod_rewrite for stuff like that. Have a look here:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
There are many possibilities and the exact commands depend on your link structure, but in principle (assuming that its about redirecting domain.com/mypageto domain.com/new/mypage) it works like that in your .htaccess:
RewriteEngine On
RewriteRule ^$ /new [L]
Edit: Of course you will have to install / activate Apaches mod_rewrite beforehand if its not already enabled.
This should be fairly simple. Use these 3 rules in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^oldpage1/?$ /new/newpage1 [L,NC,R=301]
RewriteRule ^oldpage2/?$ /new/newpage2 [L,NC,R=301]
RewriteRule ^oldpage3/?$ /new/newpage3 [L,NC,R=301]

Redirect specific URLs by analyzing the querystring using htaccess

On my current website I use parameters in querystrings to select the content shown to the user (e.g. www.domain.tld/index.php?site=linklist&page=2). I want to switch to wordpress and have all old links redirected to the new permalinks of wordpress.
When having site=linklist in the query string the user should be redirected to www.domain.tld/my-new-linklist . If the querystring contains site=about the user should be redirected to www.domain.tld/about-me ,...
How can I realize this using htaccess?
In the htaccess file in your document root, try adding these above any of your wordpress rules:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|.*)site=linklist&?($|.*)
RewriteRule ^/?index.php$ /my-new-linklist?%1%2 [L,R=301]
RewriteCond %{QUERY_STRING} (^|.*)site=about&?($|.*)
RewriteRule ^/?index.php$ /about-me?%1%2 [L,R=301]
etc.
Any other query string gets passed along, but the site=something is stripped out.

Mod_Rewrite for htaccess

The URL structure for Joomla 1.5 changed in version 2.5.
Before it was:
http://example.com/index.php?option=com_content&task=view&id=587&Itemid=73
Now it's:
http://example.com/index.php?option=com_content&view=article&id=587&Itemid=114
*Note the id and itemid numbers change based on page and while all pages have an id not all have the Itemid in the url.
While we updated all links in the database lots of people still have the old link structure so we want to edit the htaccess file so if someone enters the old structure it will forward to the right structure.
Simply put any URL entered at example.com with task=view in the url should be replaced with view=article.
Does anyone know a simply way to do this in htaccess, maybe with replace query string method and 301 redirect?
You can match against the query string using mod_rewrite's RewriteCond and the %{QUERY_STRING} variable. Then use the % backreferences in a RewriteRule
Try something like this:
RewriteCond %{QUERY_STRING} ^(.*)&task=view&(.*)$ [NC]
RewriteRule ^(.*)$ /$1?%1&view=article&%2 [R=301,L]

htaccess redirect for subdomains -> similarly-named subdirectories?

I'm restructuring a web site with a great deal of content currently parked at URLs that look like this.
http://string.domain.com/year/month/dd/string-pulled-from-title
For various reasons, I'd like to park all new content at URLs that looks like this
http://www.domain.com/blogs/string/year/month/dd/string-pulled-from-title
I'd like to make the change for future content, but don't want all the old stuff to go 404.
I believe a 301 redirect rule in my htaccess will do the trick, sending all referred traffic coming in through old links to the new formats.
But what should this rule look like? I've read a few tutorials but haven't found this exact case in any examples.
Note, I don't want to do this for all subdomains, only for about 10 specific ones. So if someone could help me figure out one of these, then I can copy paste it 10 times in my htaccess for each subdomain and be set.
Drop this into the .htaccess file of the old site (adjusting the domain to your actual one):
RewriteEngine On
RewriteRule ^(.*)$ http://example.com/blogs/string/$1 [R=301]
This will grab this part of the URL at the old site:
year/month/dd/string-pulled-from-title
and redirect it to the new site under the new location:
blogs/string/year/month/dd/string-pulled-from-title
Alternatively, if you want something a little more variable like, without having to custom fix each .htaccess, drop this in the file for each subdomain instead:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*).example.com
RewriteRule ^(.*)$ http://example.com/blogs/%1/$1 [R=301,L]
If you're redirecting to the same domain, and it includes the www, adjust the rewrite rules to the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*).example.com
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/blogs/%1/$1 [R=301,L]
Note the second RewriteCond which checks to make sure that the URL requested does not include the leading www, which may lead to an endless redirect if the destination URL itself includes www and would try and redirect that subdomain as well.
%1 grabs the first capture group from the line above.
$1 references the first capture group on the same line.

Resources