I've changed a few URLs on my OpenCart (version 1.5.6) website and then I've changed them one more time; Google started alerting me that there are dead links and now I'm trying fix things up by adding manual 301 redirects in .htaccess
: I used to do this whenever I was using WordPress.
I'm more than okay to do each link manually, I actually do prefer this method.
However, whenever I add a line in .htaccess
it tends to be ignored.
Below is the content of my .htaccess
file:
<Files *.ini>
Order deny,allow
Deny from All
</Files>
SetEnv PHPRC /home/shopurl/
Options +FollowSymlinks
Options -Indexes
<FilesMatch "\.(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
RewriteCond %{HTTP_HOST} ^shopurl.com
RewriteRule (.*) http://www.shopurl.com/$1 [R=301,L]
RewriteBase /
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]
<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
<ifModule mod_headers.c>
Header append Vary User-Agent
</ifModule>
<FilesMatch "\.(js|css|jpg|png|jpeg|gif|xml|json|txt|pdf|mov|avi|otf|woff|ico|swf)$">
RequestHeader unset Cookie
Header unset Cookie
Header unset Set-Cookie
ErrorDocument 404 'Not Found'
</FilesMatch>
How can I achieve that successfully?
Add all your RewriteRules just after your RewriteBase /
line, like this:
...
RewriteBase /
RewriteRule ^your-url$ /your-new-url [L,R=301]
RewriteRule ^your-page$ /your-new-page [L,R=301]
RewriteRule ^your-category$ /your-new-category [L,R=301]
RewriteRule ^your-product$ /your-new-product [L,R=301]
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
...
So it rewrites:
http://www.yoursite.com/your-url
- to -
http://www.yoursite.com/your-new-url
etc...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.