I was trying to edit my htaccess file to redirect from http to https.
This one works for all pages except the homepage for every language:
http://cinqueterre.a-turist.com/deu
redirects to
https://cinqueterre.a-turist.com/https://cinqueterre.a-turist.com/deu
It's a little complicated script
Here is it:
Update: I improved a little the script, now it's not such complicated, and doesn't work if I add https redirect
DirectoryIndex 1.php index.html$ index.php
ErrorDocument 404 /404.php
RewriteEngine on
Options -Multiviews
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTPS_HOST} ^www\.cinqueterre\.a\-turist\.com$ [NC]
RewriteRule (.*) https://cinqueterre.a-turist.com/$1 [R=301,L]
RewriteCond %{HTTPS_HOST} ^cinqueterre.a-turist\.com$ [OR]
RewriteCond %{HTTPS_HOST} ^www\.cinqueterre.a-turist\.com$
RewriteRule ^(rus|ita|fra|deu|ukr|pol|esp)\/index\.php$ https\:\/\/cinqueterre.a-turist\.com\/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]
#if its not a directory
RewriteCond %{REQUEST_FILENAME} !-d
#and it has a trailing slash then redirect to URL without slash
RewriteRule ^(.+)/$ /$1 [L,R=301]
Options All -Indexes
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
Try getting rid of all of your redirects, they're in the wrong place.
You need to add redirects before this rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]
And you want something like this:
RewriteCond %{THE_REQUEST} \ /+.*index\.php
RewriteRule ^(rus/|ita/|fra/|deu/|ukr/|pol/|)index\.php$ https://cinqueterre.a-turist.com/$1 [R=301,L]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?cinqueterre.a-turist\.com$ [NC]
RewriteRule ^(.*)$ https://cinqueterre.a-turist.com/$1 [R=301,L]
Related
This simple rule should redirect to url without one word (picture-display):
RewriteRule en/catalog/picture-display/(.*)$ en/catalog/$1 [L,NC,R=302]
But it redirect from www.example.com/en/catalog/picture-display/something to www.example.com/en. What I am doing bad?
Before this rule I have this. Would not influence it?
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
EDIT
Whole .htaccess:
path/.htaccess
Header unset ETag
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(ico)$">
Header set Cache-Control "max-age=29030400"
</FilesMatch>
</IfModule>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^/?$ /public/index.php [L]
RewriteRule ^\.htaccess/?$ - [NC,F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$ [NC]
RewriteRule ^(.*)/?$ /public/$1
RewriteRule ^(cs/katalog)/obrazkove-zobrazeni/(.*)/?$ $1/$2 [L,NC,R=302]
RewriteRule ^(en/catalog)/picture-display/(.*)/?$ $1/$2 [L,NC,R=302]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [QSA,NC,L]
htaccess to route from documentRoute:
path/public/.htaccess (document route) - there is index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
Result of cmd
Please try add rule:
RewriteRule ^en/catalog/picture-display/(.*)$ en/catalog/$1 [L,NC,R=302]
before line with RewriteRule ^/?$ /public/index.php [L]
Please try following htaccess rules in your file. Please make sure to clear your browser cache before testing your URLs.
Header unset ETag
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(ico)$">
Header set Cache-Control "max-age=29030400"
</FilesMatch>
</IfModule>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [F,L]
RewriteCond %{REQUEST_URI} !^/public [NC]
RewriteRule ^(.*)/?$ /public/$1 [L]
RewriteRule ^/?$ /public/index.php [L]
RewriteRule ^public /public/index.php [QSA,NC,L]
RewriteRule ^\.htaccess/?$ - [NC,F]
RewriteRule ^(en/catalog)/picture-display/(.*)/?$ $1/$2 [L,NC,R=302]
RewriteRule ^(cs/katalog)/obrazkove-zobrazeni/(.*)/?$ $1/$2 [L,NC,R=302]
Keep your path/public/.htaccess (document route) like as follows:
RewriteOptions Inherit
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
Have it this way in your site root .htacccess:
RewriteEngine On
RewriteRule ^\.htaccess/?$ - [NC,F]
# add www and turn on https in same rule
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=302,L,NE]
RewriteRule ^(cs/katalog)/obrazkove-zobrazeni/(.*)/?$ /$1/$2 [L,NC,R=302]
RewriteRule ^(en/catalog)/picture-display/(.*)/?$ /$1/$2 [L,NC,R=302]
RewriteRule ^/?$ /public/index.php [L]
RewriteCond %{REQUEST_URI} !^/public/ [NC]
RewriteRule .* public/$0 [L]
Correct htaccess which do what I wanted is:
RewriteEngine On
RewriteRule ^cs/katalog/obrazkove-zobrazeni/(.*)/?$ /cs/katalog/$1 [L,NC,R=302]
RewriteRule ^en/catalog/picture-display/(.*)/?$ /en/catalog/$1 [L,NC,R=302]
RewriteRule ^\.htaccess/?$ - [NC,F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$ [NC]
RewriteRule ^(.*)/?$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [QSA,NC,L]
I would like to thank to #RavinderSingh13 and others which tried out help me, but their solutions didn't work unlike mine.
I have managed to remove the .php extension using the below htaccess code but the issue i face now is index.php shows like www.site.com/index
could someone help me out to rename it to www.site.com/home instead of /index?
Here is my complete htaccess file
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ pages.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
<IfModule mod_deflate.c>
<FilesMatch "\.(css|x?html?|php)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType text/html "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F,L]
</IfModule>
Really appreciate your kind help.
Could you please use following Rules set in your .htaccess file once. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine On
RewriteBase /
##new redirection rules here for index.php to home.
RewriteRule ^index\.php/?$ /home? [R=301,NC,L]
RewriteRule ^home/?$ site/index.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ pages.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
<IfModule mod_deflate.c>
<FilesMatch "\.(css|x?html?|php)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType text/html "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [NC,OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) [NC]
RewriteRule .* index.php [F,L]
</IfModule>
In the code above are the lines that i have in my .htaccess file. The problem is when is a single command works like a charm but when i add many commands doesnt work any of thems. Please can anyone help me to find the error.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{HTTP_HOST} !^www.marinoswood.gr$ [NC]
RewriteRule ^(.*)$ http://www.marinoswood.gr/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^185\.4\.133\.44
RewriteRule (.*) http://www.marinoswood.gr/$1 [R=301,L]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
</IfModule>
A few rules of thumb:
Always put your redirect rules before any internal rewrite rules, so anything with an R flag must be first
If you are using the F flag, in a rule to block access, those rules must be before all rules, including your redirect rules (ones with R flag)
Rewrite conditions only apply to the immediately following rule, so if the conditions need to be applied to multiple rules, those conditions must be repeated for each of them
Those .php rules are completely broken and need to be rewritten
Additionally, the mod_expires directives do not impact the rules.
So maybe you want something like?:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
RewriteCond %{HTTP_HOST} !^www.marinoswood.gr$ [NC]
RewriteRule ^(.*)$ http://www.marinoswood.gr/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^185\.4\.133\.44
RewriteRule (.*) http://www.marinoswood.gr/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/]+)/$ $1.php [L]
RewriteCond %{DOCUMENT_ROOT}/$1/$2.php -f
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php [L]
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
</IfModule>
I tried different redirects from one page to another (page moved to another url) but nothing is really working - I keep getting 404 page.
I would like to move http://www.staskka.com/mladinska-postelja-gasilec.html to http://www.staskka.com/otroska-oprema/otroske-posteljice/mladinska-otro%C5%A1ka-postelja-gasilec.html
Nothing happens. Still 404 page not found.
Code in .htaccess was:
# BEGIN Permanent URL redirects
RewriteRule ^mladinska-postelja-gasilec\.html$ /pohistvo/otroske-posteljice/mladinska-otroška-postelja-gasilec/? [L,R=301,NC]
I also have redirection from non www to www.. and works fine..
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
I only need to redirect some of the URL's because I put them in category and a lot of this sites are ranked on google very well-- Could anybody help me out, please?
Your help is much appreciated .. thanks.
Oh, and I use OC 1.5.1.3.
EDIT: This is the whole .htaccess
rewriteengine on
rewritecond %{HTTP_HOST} ^www.djecje-kuhinje.com$ [OR]
rewritecond %{HTTP_HOST} ^djecje-kuhinje.com$
rewriterule ^djecje-kuhinje-com\/ "http\:\/\/shop\.djecje-kucice\.com\/" [R=301,L] #52b5421b82424
rewritecond %{HTTP_HOST} ^www.otroska-kuhinja.si$ [OR]
rewritecond %{HTTP_HOST} ^otroska-kuhinja.si$
rewriterule ^otroska-kuhinja\/ "http\:\/\/www\.otroskekuhinje\.si\/" [R=301,L] #51f13a48f336e
rewritecond %{HTTP_HOST} ^kidkraft.staskka.com$
rewriterule ^kidkraft\/ "http\:\/\/www\.staskka\.com\/" [R=301,L] #50f3d3a25618d
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
##BEGIN MOBILE (do not edit below this line)
RewriteBase /
##END MOBILE
rewriterule test\.htm http://www.google.com [R]
rewritecond %{HTTP_USER_AGENT} ((.*iPhone.*)|(.*iPod.*)|(.*BlackBerry.*)|(.*Android.*Mobile.*)|(.*Windows\ CE.*)|(.*IEMobile.*)|(.*Opera\ Mini.*)|(.*Opera\ Mobi.*))
rewritecond %{HTTP_COOKIE} !dm_show_classic
rewritecond %{QUERY_STRING} !no_redirect=true [NC]
rewritecond %{HTTP_HOST} ^www\. [NC,OR]
rewritecond %{HTTP_HOST} ^[0-9a-z-]+\.[a-z]+$ [NC]
rewritecond %{REQUEST_URI} ^/_dm/s/ [NC,OR]
rewritecond %{REQUEST_FILENAME} !\.(jpg|gif|png|css|js|txt|ico|pdf|bmp|tif|mp3|wav|wma|asf|mp4|flv|mpg|avi|csv|doc|docx|xls|xlsx|ppt|pptx|zip|rar|tar|gz|dmg|iso)$ [NC]
rewriterule ^(.*)$ http://mobile.staskka.com/ [R,L]
rewriterule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
rewriterule ^googlebase.xml$ index.php?route=feed/google_base [L]
rewriterule ^download/(.*) /index.php?route=error/not_found [L]
rewritecond %{REQUEST_FILENAME} !-f
rewritecond %{REQUEST_FILENAME} !-d
rewritecond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
rewriterule ^([^?]*) index.php?_route_=$1 [L,QSA]
# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/pdf "access plus 1 week"
ExpiresByType text/x-javascript "access plus 1 week"
ExpiresByType application/x-shockwave-flash "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 week"
ExpiresDefault "access plus 1 week"
</IfModule>
## EXPIRES CACHING ##
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
# BEGIN Permanent URL redirects
RewriteRule ^mladinska-postelja-gasilec\.html$ /pohistvo/otroske-posteljice/mladinska-otroška-postelja-gasilec/? [L,R=301,NC]
RewriteCond %{SCRIPT_FILENAME} !-s
RewriteRule (.*) index.php?path=$1 [QSA,L]
From what i notice in the code the problem lies here:
rewriterule ^([^?]*) index.php?_route_=$1 [L,QSA]
since having a L flag, it means that after url call the server processes it and ends there, meaning that whatever you write after that if the url is caught in the conditions above will stop there.
So in your specific case you need to add (notice thesame without L Flag as you need Opencart to process it afterwards):
RewriteRule ^mladinska-postelja-gasilec\.html$ /pohistvo/otroske-posteljice/mladinska-otroška-postelja-gasilec/? [R=301,NC]
after this line
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
let me clarify that i am not certain if the code you use is the one that matches the behavior you want it to. But the position is the correct one. Also since in my comment i stated that you need to add these rules at the end, this is for handling external domains mostly, for your case (internal url handling) this the way to achieve it.
I'm attempting to redirect an internal link via .htaccess file and it's not working. Below is my .htaccess file '# Redirects'.
How might I better structure the code to allow working redirection links?
# Use PHP 5.3
AddType application/x-httpd-php53 .php
# Redirect www to non-www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# Redirects
Redirect 301 /oldpage http://domain/newpage
# Start Hotlink Protection
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
# EXPIRES CACHING
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/js "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
Your redirect statement is part of mod_alias, but all the rest of the rewrite rules you have belong to mod_rewrite. Those two modules processes the request at different points of the processing pipeline, so if you use them concurrently, sometimes they'll not play nicely with each other. You should just use mod_rewrite in this case as well as putting the redirect rule BEFORE your wordpress routing rules. This is because wordpress will route what you actually want to redirect.
So:
# Use PHP 5.3
AddType application/x-httpd-php53 .php
# Redirect www to non-www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#### INSERT THE REDIRECTS HERE
# Redirects
RewriteRule ^oldpage(.*)$ http://domain/newpage$1 [L,R=301]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
### Remove the redirect from here
# Start Hotlink Protection
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
And then the rest of your htaccess file