Page 1 of 1
mod rewrite question
Posted: Tue Dec 13, 2016 1:01 am
by matt71
Hello
I'm looking to do a redirect of the native contact form (/index.php?route=information/contact) to my own contact form (/contact) using mod_rewrite.
I have the following in my .htaccess file, but it doesn't appear to work. Any suggestions would be appreciated?
Code: Select all
Redirect 301 /index.php?route=information/contact http://www.mywebsite.com/contact
Thanks
Matt
Re: mod rewrite question
Posted: Tue Dec 13, 2016 1:38 am
by angela
In:
catalog/controller/startup/seo_url.php:
Find:
Replace with:
Code: Select all
} elseif ($data['route'] == 'information/contact') {
$url .= '/contact';
unset($data[$key]);
} elseif ($key == 'path') {
Remove what you did in your .htaccess, and above this:
Code: Select all
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
add:
Code: Select all
RewriteRule ^contact$ index.php?route=information/contact [L]
No need to do a 301 to achieve what you are trying to do.
You can also duplicate the syntax to do all of the default non-SEO url's to make them prettier by changing the route & htaccess flags accordingly.
Keep in mind, if you edit the controller directly, you'll need to re-apply your fixes when you upgrade your OpenCart install, so always keep a backup.
Re: mod rewrite question
Posted: Tue Dec 13, 2016 1:53 am
by simonpieman
Angela is right
For redirect rule you can add the type of redirect at the end,. i.e.
your code [NC,R=301,L]
Re: mod rewrite question
Posted: Tue Dec 13, 2016 6:22 am
by matt71
Thanks for the reply. Do I need to change the controller code or can I just revise the htaccess?
Matt
Re: mod rewrite question
Posted: Wed Dec 14, 2016 3:00 am
by angela
matt71 wrote:Thanks for the reply. Do I need to change the controller code or can I just revise the htaccess?
Matt
Both, else it won't work properly.
Back up before you edit - that way if something goes wrong, easy to undo.
Back up after, because when you upgrade you'll need to re-apply.
Re: mod rewrite question
Posted: Thu Dec 22, 2016 9:02 pm
by QuinnD
Thank you angela ... I am not OP but this answered the question i needed answering..
This isnt needed now as i have done this using separate code for each page as described above but for future reference and to cut down the lines of code needed how can you put all similar URLs into an array, then use a variable for the seo_url.php code
ie, all the account/* urls
product/*
common/*
information/*
ECT.
and the htaccess rewite code would need to pick up the variable used for each page type like it does for products and categories
Thanks