I just migrate my site from asp to opencart. In .htaccess I would like to do some redirect so that my customer can use back the old link to access
inside .htaccess
redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads
For Contact Us that work perfectly, however, for the downloads url, it didn't work correct.
when I access to http://www.example.com/downloads.asp it will redirect to http://www.example.com/downloads?_route_=downloads.asp
and Opencart show it is page not found.
For the http://www.example.com/downloads we had set SEO friendly URL in the backend system.
We able to access with
http://www.example.com/information/downloads
http://www.example.com/downloads
but we not able to access with normal link
http://www.example.com/index.php?route=information/downloads
The folowing is my full .htaccess
# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini)">
Order deny,allow
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads
============ANOTHER TESTING========================
I did some testing on this on my localhost I found out it is a quit interesting result. However, my problem still haven't solve.
I run the .htaccess from http://localhost/example and http://example (added virtual directory)
For http://localhost/example
redirect 301 /example/downloads.asp http://localhost/example/downloads/
and
For http://example
redirect 301 /downloads.asp http://example/downloads/
Then I tried, redirect to my live version link, from localhost (http://example)
redirect 301 /downloads.asp http://www.example.com/downloads/
I access to http://example/downloads.asp
The browser redirect to me
http://www.example.com/downloads?route=downloads.asp
NOTED
In LIVE version, I did not added any redirect code [VERY SURE FOR THIS]
But in Live version, I am to access directly with enter
http://www.example.com/downloads
I am not sure why from localhost redirect 301 to live version will come out
http://www.example.com/downloads?route=downloads.asp
Any idea?
Solution Found:
.htaccess redirect 301 working with opencart v1.5.4.1
Additional code needed for... (and credits of this fix):
https://github.com/opencart/opencart/pull/142
... replace contents of:
- catalog/controller/common/seo_url.php
- system/library/url.php
Redirect Fine:
RewriteRule contacto http:....com/index.php?route=information/contact [R=301,L]
Redirect Not Working:
redirect 301 contacto http:....com/index.php?route=information/contact
Verified.
Put it in front of router. Also add $ after .asp and ^ in front.
# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini)">
Order deny,allow
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
redirect 301 ^contact.asp$ http://www.example.com/index.php?route=information/contact_us
redirect 301 ^downloads.asp$ http://www.example.com/downloads
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
Why don't you redirect contact to /information/contact_us instead of index.php?route=information/contact_us ?
You can try a "?" at the end of the redirect url if it is not present there like 2nd url(it worked for me) :
redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads?
Related
Recently my site got hacked, and tons of pages were generated. Most of them end with strings like ?_t=77, ?_t=97, and ?_t=56 etc. Basically, the ?_t= part is common in all of them.
How do I create a .htaccess rule to redirect all the links with ?_t= to home?
Some redirects I've already created:
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /profile/1320172681 /u/DanLiu
Redirect 301 /profile/387899125 /u/LuckyMaheshwari
Redirect 301 /profile/15379797 /u/manishchopra
Redirect 301 /profile/335596945 /u/MatthewNord
Redirect 301 /profile/94097446 /u/abhimanyu
</IfModule>
Thanks
With your shown attempts/samples, please try following htaccess rules. Please make sure to clear your browser cache before testing your URLs.
<IfModule mod_rewrite.c>
##making your Rewrite engine ON here.
RewriteEngine On
##Rewriting urls with ending with ?_t=digits to home page here.
RewriteCond %{QUERY_STRING} ^_t=\d+/?$ [NC]
RewriteRule ^ / [R=301,L,QSD]
##Rewriting home page url to index.php here.
RewriteRule ^/?$ index.php [QSA,L]
###put your rest of htaccess Rules from here onwards.
Redirect 301 /profile/1320172681 /u/DanLiu
Redirect 301 /profile/387899125 /u/LuckyMaheshwari
Redirect 301 /profile/15379797 /u/manishchopra
Redirect 301 /profile/335596945 /u/MatthewNord
Redirect 301 /profile/94097446 /u/abhimanyu
</IfModule>
I am palling to migrate my website from the .co.nz to the .com but need to setup a 301 redirect so all of the individual pages will still be routed properly without any 404 pages from .co.nz version
All https://
I want "https://www.example.co.nz/" to go to "https://www.example.com"
Which will also redirect
https://www.example.co.nz/contact to go to https://www.example.com/contact
https://www.example.co.nz/men to go to https://www.example.com/men
Many Thanks
This should do the trick:
Redirect 301 / https://www.new-example.com/
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !new-example.com$ [NC]
RewriteRule ^(.*)$ https://new-example.com/$1 [L,R=301]
You put this in the .htaccess file of the .co.nz domain. This will redirect all your content and subfolders to their appropriate subfolders on the new domain (so example.me/subfolder to example.com/subfolder) AND also force redirect to https part.
We've moved a site to another domain and setup the htacess as bellow, but how can i set a rule "if page dosnt exist - (ie 404 error) redirect to new site homepage." To be used as a fall back, if someone follows a broke url to our old site.
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.oldsite\.co\.uk)(:80)? [NC]
RewriteRule ^(.*) http://oldsite.co.uk/$1 [R=301,L]
Redirect permanent http://oldsite.co.uk http://newsite.co.uk
Redirect permanent http://oldsite.co.uk/index.html http://newsite.co.uk
Redirect permanent http://oldsite.co.uk/contact-us.html http://newsite.co.uk/contact-us.html
Redirect permanent http://oldsite.co.uk/bespoke-furniture.html http://http://newsite.co.uk/bespoke-furniture.html
Redirect permanent http://oldsite.co.uk/about-us.html http://newsite.co.uk/about-us.html
Redirect permanent http://oldsite.co.uk/how.html http://newsite.co.uk/about-us.html
order deny,allow
You could simply use this.
ErrorDocument 404 http://newsite.co.uk
I am having trouble redirecting an entire directory that no longer exists on our server.
All variations of the following are not working and I simply get a 404 Page Not Found.
.htaccess file looks like this:
redirect 301 /non_existent_directory/ http://my.website.com/existent_directory/
Is it possible to use the Redirect 301 directive for this? Or is this only solvable by mod_rewrite?
Thanks
I even tried:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?my\.website\.com\/non_existent_directory\/$ [NC]
RewriteRule ^(.*)$ http://my.website.com/existent_directory/ [R=301,L]
No luck...
From the Redirect documentation, I would say
Redirect 301 /non_existent_directory http://my.website.com/existent_directory
or
Redirect 301 /non_existent_directory /existent_directory
should work, provided you are allowed to use this in a .htaccess file. See also Troubleshooting .htaccess files. You should test without 301 though, to prevent caching of bad redirects by the client.
If this doesn't work, you can try a RewriteRule of course
RewriteEngine On
RewriteRule ^/?non_existent_directory(.*)$ /existent_directory$1 [R,L]
But this is equivalent to the above Redirect directive.
I'm using htaccess rewrite engine to make urls look nice,
from www.mysite.com/index.php?pag=home to www.mysite.com/pag/home
it works fine with this rule
RewriteRule ^pag/([^/]+)$ index.php?pag=$1 [L,QSA,NC]
but when I go to www.mysite.com it redirects me to www.mysite.com/index.php
is there a way to redirect to www.mysite.com/pag/home?
I tried
redirect 301 /index.php http://www.mysite.com/pag/home
but when i try to go to www.mysite.com the browser gives my "page do not exsist error"
This is the rule that Drupal uses to make it's pretty urls, yours should be extremely similar:
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Your rule only matches on urls that have pag in them, but you're really wanting to hit every url.
the problem was in this redirect rule
redirect 301 /index.htm http://www.mysite.com/index.php