Archived topic
.htaccess Questions on Redirection
5 replies · Started by John on December 30, 2016
Been struggling a bit with our .htaccess file and how it handles redirects. The current .htaccess file services not only a Wordpress install, but also an OpenCart install and also SSL certificate - and I believe it is getting "confused".
Is there anyone out there that is proficient with .htaccess configuration for redirection that might be looking for a bit of a challenge to look at? I am not looking for a handout here, rather I think someone with knowledge might be able to knock this off fairly quick.
I can be reached here or maybe offlist would be better at john@pcboard.ca
Thanks...John
Have you tried using a plugin to do it for you?:
https://en-ca.wordpress.org/plugins/simple-301-redirects/
As long as everything in your .htaccess file is correct, it shouldn't get confused regardless of the amount of data in it.
I will have to give that a try. Not sure it will work for URL outside of the WP directory structure (I will have to verify that). Where I am having concerns today is that when I run some tests on the root site (www.pcboard.ca) I find that I have 302 redirects in place, as opposed to the preferred 301 perm redirects.
Seems that the configuration is getting confused between http://www.pcboard.ca, https://www.pcboard.ca, http://pcboard.ca and https://pcboard.ca
I am assuming it is because of the .htaccess file - but not sure.
I have not been able to wrap my head around the structure of the file yet.
Here is what we have today:
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^blog.pcboard.ca
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^(.*)$ http://pcboard.ca/blog/$1 [L,NC,QSA]
#RewriteCond %{HTTP_HOST} ^pcboard\.ca [NC]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^(.*)$ https://www.pcboard.ca/$1 [R,L]
# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.
# 2. In your opencart directory rename htaccess.txt to .htaccess.
# For any support issues please visit: http://www.opencart.com
Options +FollowSymlinks
# Prevent Directoy listing
Options -Indexes
# Prevent Direct Access to files
<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
Order deny,allow
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^system/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)
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteEngine On
AddHandler application/x-httpd-php5 .html .htm
Hmm, lots going on. Unfortunately I'm definitely not an export on .htaccess. You might have better luck asking for help on stackoverflow.
Tom... Thanks for your assistance - I have been playing around with the htaccess file today and made some headway after lots of reading. Seems to be some magic going on in there and you just have to rub it the right way.
Again - thanks for you guidance.
john
No problem - glad you're making progress :)