SSL certificate HTTPS redirect disable via Htaccess - .htaccess

So it redirects to https but as I don't have SSL certificate anymore it needs to be disabled, tried to remove the Force SSL part didn't do anything same for the force web www didn't do any change either
another thing is when I go to my site it automatically adds www. twice so wwww.www.(domainname)
here's the htaccess
<IfModule mod_expires.c>
ExpiresActive on
# Your document HTML
ExpiresByType text/html "access plus 0 seconds"
# Media: images, video, audio
ExpiresByType audio/ogg "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 video/mp4 "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# CSS and JavaScript
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/css "access plus 1 year"
</IfModule>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
### Force web (www) on all URLs
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
### Force SSL (https) on all URLs
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
### Remove trailing slash from all URLs
RewriteRule ^(.*)/$ $1 [R=301,L]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
RewriteRule ^buy-([a-z0-9-]+)$ buy.php?game=$1 [NC,L,QSA]
# Redirect proper URL to SEO-friendly for buy.php
RewriteCond %{THE_REQUEST} buy\.php\?game=([a-z0-9-]+)\s [NC]
RewriteRule ^ buy-%1? [R=301,L]
# Internally link SEO-friendly with proper URL for buy.php
RewriteRule ^buy-([a-z0-9-]+)$ buy.php?game=$1 [L]
# Redirect proper URL to SEO-friendly for sell.php
RewriteCond %{THE_REQUEST} sell\.php\?game=([a-z0-9-]+)\s [NC]
RewriteRule ^ sell-%1? [R=301,L]
# Internally link SEO-friendly with proper URL for sell.php
RewriteRule ^sell-([a-z0-9-]+)$ sell.php?game=$1 [L]
# Redirect proper URL to SEO-friendly for testimonials.php (with pages)
RewriteCond %{THE_REQUEST} testimonials\.php\?page=([0-9-]+)\s [NC]
RewriteRule ^ testimonials/%1? [R=301,L]
# Internally link SEO-friendly with proper URL for testimonials.php (with pages)
RewriteRule ^testimonials/([0-9-]+)$ testimonials.php?page=$1 [L]
# Redirect proper URL to SEO-friendly for recover.php (with code)
RewriteCond %{THE_REQUEST} recover\.php\?code=([a-z0-9-]+)\s [NC]
RewriteRule ^ recover/%1? [R=301,L]
# Internally link SEO-friendly with proper URL for recover.php (with pages)
RewriteRule ^recover/([a-z0-9-]+)$ recover.php?code=$1 [L]
# Redirect proper URL to SEO-friendly for index.php (with order ID)
RewriteCond %{THE_REQUEST} index\.php\?order=([a-zA-Z0-9-]+)\s [NC]
RewriteRule ^ o/%1? [R=301,L]
# Internally link SEO-friendly with proper URL for index.php (with order ID)
RewriteRule ^o/([a-zA-Z0-9-]+)$ index.php?order=$1 [L]
# Redirect proper URL to SEO-friendly for any standard page
RewriteCond %{THE_REQUEST} \s/+(account|testimonials|contact|privacy|terms|cart|recover|faq|login|register|banned)\.php [NC]
RewriteRule ^ /%1? [R=301,L]
# Internally link SEO-friendly with proper URL for any standard page
RewriteRule ^(account|testimonials|contact|privacy|terms|cart|recover|faq|login|register|banned)$ $1.php [NC,L]

It is likely that you had a 301 redirect from http to https in your configuration. Simply removing this redirect and retrying will not help since 301 is the code for a permanent redirect which means that the browser will remember this redirect, i.e. it will visit https:// instead of http:// since the cached redirect says so and will not even try to visit http://.
To fix this you need to have both the redirect removed and the browser cache cleared - and then can you retry. And yes, this affects every client which has visited your site. Since you cannot clear the browser cache from every client you better install a new certificate. Once you have one you can redirect all users from https:// to http:// and after a while most browsers should have gotten the message that http:// is the way to go so that you can remove the redirect and the certificate. Or even better, just stay with https:// - there are CA like Let's Encrypt which provide you with free certificates.

Related

New .htaccess breaks site

I'll admit I'm brand brand new to coding. I am trying to help a client who uses Dreamweaver to publish their website on a server at their headquarters. I asked their IT department to add code to their .htaccess file that would help redirect non https to https and force www but also remove the .html extensions. I am pretty sure the code is correct but when they added it, the site broke.
The old .htaccess file had the following code:
/var/www/html/HRT/.htaccess
RedirectMatch 301 ^/here(/.+?)?$ http://go.example.com/here
RedirectMatch 301 ^/HERE(/.+?)?$ http://go.example.com/here
RedirectMatch 301 ^/there(/.+?)?$ http://go.example.com/there
RedirectMatch 301 ^/THERE(/.+?)?$ http://go.example.com/there
I changed the urls for privacy. Just having this worked before. But when I asked them to add the below code, it broke. Not sure even where to start.
# FORCE HTTPS, FORCE WWW and REMOVE HTML #
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
RewriteRule ^([^/]+)\.html$ $1 [QSA,L]
# EXPIRES CACHING VIA HTACCESS #
<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/html "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 1 month"
</IfModule>
I should note that during the previous week they added to their http.config file for expiring cache too so I'm not sure that would cause this problem. Just trying to think of all the things they've done before this error.
Thanks in advance.
RewriteRule ^([^/]+)\.html$ $1 [QSA,L]
You can't simply "remove" the .html file extension like that in .htaccess - it will most certainly break your site.
In fact, you can't remove the file extension by editing .htaccess alone. It's a two stage process:
You need to remove the .html extension on all your URLs - in your application. All your internal links need to be updated to omit the .html extension.
You then use .htaccess to internally rewrite the request without an extension, back to the real filesystem path that includes the .html extension. Underneath it all, your filesystem paths have not changed.
For example:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.html [L]
This assumes that your URLs do not otherwise contain dots (.) - except if they are requesting a file directly (eg. .js, .css, .jpg, etc.)
You will also need to ensure that MultiViews is disabled (if not already) for this to work properly. ie. Include the following at the top of your .htaccess file:
Options -MultiViews
If you are changing an existing URL structure then you'll need to implement an external redirect to physically remove the .html extension from the URL in order to preserve SEO. However, you should only implement this if you have completed step #1 (and #2) above and removed the .html extension on all your internal URLs (otherwise your users will suffer an external redirect on every link when navigating your site, which will be slow and double the requests hitting your server).
For example, the following redirect would need to go before the rewrite (above):
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule (.+)\.html$ /$1 [R=302,L]
The condition that checks against the REDIRECT_STATUS environment variable ensures that we target only direct requests and not the rewritten request.
Note that this is currently a 302 (temporary) redirect. Only change it to a 301 (permanent) redirect once you have confirmed that it works OK - in order to avoid caching issues.
In Summary
# Disable MultiViews
Options -MultiViews
Then add the following below your canonical HTTP to HTTPS and non-www to www redirects:
# Redirect to remove the ".html" extension from direct requests
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule (.+)\.html$ /$1 [R=302,L]
# Internal rewrite to re-append the ".html" extension for the internal request
# NB: Exclude requests for directories
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.html [L]

Htaccess redirect happens different for www and non www

I have redirected all non www to www url using the following
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Next ,
The final url for categories required is :
http://www.slidecorner.com/category/Design
I have used this for achieving this
RewriteRule ^/?category/(.*) category.php?ctitle=$1
This also works, but when i check this url in any redirect checking websites , the "www" version of url is perfect, but "non www" url internally redirects to :
http://www.slidecorner.com/category.php/Design?ctitle=Design
Is this good for a search engine ? Please advise
Update : Tried [L] flag also , and rewritebase is already there. Attached full htaccess for reference
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^docs$ docs.php
RewriteRule ^category$ category.php
RewriteRule ^categories$ categories.php
RewriteRule ^members$ members.php
RewriteRule ^upload$ upload.php
RewriteRule ^search$ search.php
RewriteRule ^account$ account.php
RewriteRule ^logout$ logout.php
RewriteRule ^login$ login.php
RewriteRule ^signup$ signup.php
RewriteRule ^feeds$ feeds.php
RewriteRule ^mydocs$ mydocs.php
RewriteRule ^myfav$ myfavoritedocs.php
RewriteRule ^doc/(.*)/(.*) viewdoc.php?did=$1&title=$2
RewriteRule ^syndicate/docs/(.*)/(.*) syndicatedocs.php?filter=$1&title=$2
RewriteRule ^download/doc/(.*)/(.*) downloaddoc.php?DID=$1&title=$2
RewriteRule ^resetpassword/(.*) resetpassword.php?code=$1
RewriteRule ^confirmemail/(.*) confirmemail.php?code=$1
RewriteRule ^resendconfirmation/(.*) resendconfirmation.php?userid=$1
RewriteRule ^members/profile/(.*)/(.*) memberprofile.php?pid=$1&username=$2
RewriteRule ^/?category/(.*) category.php?ctitle=$1 [L]
# to hide jpg images
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?slidecorner.com[NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?slidecorner.*$ [NC]
RewriteRule \.(jpeg|jpg)$ - [F]
# to hide jpg images
# for sending compressed data to load faster
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
# for sending compressed data to load faster
</IfModule>
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
#non www redirect ,since the above doesnt redirect
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,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/html "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 1 month"
</IfModule>
## EXPIRES CACHING ##
<IfModule mod_security.c>
# Turn off mod_security filtering.
SecFilterEngine Off
# The below probably isn't needed,
# but better safe than sorry.
SecFilterScanPOST Off
</IfModule>
Options -Indexes
Update : I found the issue is due to this code
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
I removed that and the url is fine . Also the non www to www redirection is completely stopped because i removed that
Is there anything wrong with the above code ?
The order of directives (within modules) matters in .htaccess. Whilst your question suggests you are performing the canonical www redirect first, you actually have this after the internal rewrites in your .htaccess files and this is certainly a problem in this case. (Although the exact output you are getting from the "checking tool/website" would seem to be a fault of the "tool" IMO.)
Generally, you should always have external redirects before internal rewrites.
With the internal rewrite first you ending up losing your "pretty URL". What actually happens when you access the non-canonical (non-www) URL http://example.com/category/Design is:
Internal rewrite to:
/category.php?ctitle=Design
External redirect to:
http://www.example.com/category.php?ctitle=Design
It is important to realise that the L (last) flag only halts the current processing of the rule set. If an internal or external redirect has occurred then process starts again!

.htaccess 301 redirect if page has a trailing slash

lets say my domain page is
www.website.com/about
and then a user puts
www.website.com/about/ (a trailing slash) at the end
it returns the same page, great. However search engines may see this as duplicate content as it could be seen as 2 pages.
if the user puts a trailing slash at the end of a page i want them to do a 301 redirect to the correct page.
my .htaccess file looks like this
# Begin cache control #
ExpiresActive on
ExpiresDefault "now plus 1440 minutes"
ExpiresByType text/html "now plus 1440 minutes"
<FilesMatch "\.(css|png|bmp|ico|htm|gff|html|js|jpg|jpeg|gif|gcf)$">
FileETag MTime Size
ExpiresDefault "now plus 1440 minutes"
</FilesMatch>
# End cache control #
Options +FollowSymLinks -MultiViews
AddOutputFilterByType DEFLATE text/html image/png image/jpeg image/jpg text/css text/javascript
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L,NC]
Does any one know how I can achieve this as everything im trying will not work.
You can insert this rule just before your last rule to remove trailing slash:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]

IP banning via .htaccess not working

Liteserver on a Shared access host here.
I'm trying to get rid of a lot of bots who waste my resources for nothing.
I can successfully restrict access to some of them using a specific User Agent, but I can't ban their IP addresses, together with those of a lot of chinese ones who are constantly scanning my website. I am still seeing AhrefsBot IP (5.10.83.44) in the access log, even if its IP is banned (see the last line of the htaccess file). The rules should already be inherited by /gallery subfolder.
5.10.83.44 - - [07/Sep/2013:00:56:42 +0200] "GET /gallery/addfav.php?pid=858&referer=displayimage.php%3Fpid%3D858
HTTP/1.1" 302 156 "-" "Mozilla/5.0 (compatible; AhrefsBot/5.0;
+http://ahrefs.com/robot/)"
Root's .htaccess
AddDefaultCharset UTF-8
<IfModule mod_headers.c>
<FilesMatch "\.(js|css)$">
Header append Vary Accept-Encoding
Cache-Control: Private
</FilesMatch>
</IfModule>
RewriteEngine on
#inherit from root htaccess and append at last, necessary in root too
RewriteOptions inherit
#block bad bots
RewriteCond %{HTTP_USER_AGENT} ^$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^spider$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^robot$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^crawl$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*)AhrefsBot(.*) [OR]
RewriteCond %{HTTP_USER_AGENT} ^discovery$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]
RewriteCond %{HTTP_USER_AGENT} 360Spider [OR]
RewriteCond %{HTTP_USER_AGENT} Ezooms/1.0 [OR]
RewriteCond %{HTTP_USER_AGENT} MJ12bot/v1.4.4
RewriteRule ^(.*)$ http://go.away/
#include caching for images
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/jpg "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/x-icon "access plus 360 days"
ExpiresByType text/css "access plus 1 day"
ExpiresByType text/html "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType text/x-javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType application/x-shockwave-flash "access plus 1 week"
ExpiresByType font/truetype "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/x-font-otf "access plus 1 month"
</IfModule>
RewriteCond %{HTTP_HOST} ^id.foo.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.id.foo.com$
RewriteRule ^/?$ "http\:\/\/foo\.myopenid\.com\/" [R=301,L]
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#ban bots and stuff
order allow,deny
deny from 113.212.68.114
deny from 77.232.159.95
deny from 1.12.0.0/14
deny from 1.24.0.0/13
deny from 1.32.0.0/16
[...]
deny from 5.10.83.0/23
allow from all
/gallery subfolder .htaccess
RewriteEngine On
#inherit from root htaccess and append at last
RewriteOptions inherit
##/**************************************************
## Coppermine 1.5.x Plugin - sef_urls
## *************************************************
## Copyright (c) 2003-2007 Coppermine Dev Team
## *************************************************
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
## ********************************************
## $HeadURL$
## $Revision$
## $LastChangedBy$
## $Date$
## **************************************************/
#Options FollowSymLinks SymLinksIfOwnerMatch
# RewriteEngine on
# Uncomment the following line if your webserver's
# URL is not directly related to physical file paths.
# Update "YOUR_COPPERMINE_ROOT" (just / for root)
#RewriteBase /gallery
#
# Language translation
#
RewriteRule cerca.html(.*) search.php$1 [NC]
RewriteRule contatti.html(.*) contact.php$1 [NC]
RewriteRule (.*)migliore(.*) $1toprated$2 [NC]
RewriteRule (.*)popolari(.*) $1topn$2 [NC]
RewriteRule (.*)osservazionedi(.*) $1lastcomby$2 [NC]
RewriteRule (.*)osservazione(.*) $1lastcom$2 [NC]
RewriteRule (.*)pagina(.*) $1page$2 [NC]
RewriteRule (.*)listautenti(.*) $1usermgr$2 [NC]
RewriteRule (.*)profilo(.*) $1profile$2 [NC]
RewriteRule (.*)miniature(.*) $1thumbnails$2 [NC]
RewriteRule (.*)mostra(.*) $1displayimage$2 [NC]
RewriteRule (.*)novitadi(.*) $1lastupby$2 [NC]
RewriteRule (.*)novita(.*) $1lastup$2 [NC]
RewriteRule (.*)cerca(.*) $1search$2 [NC]
RewriteRule (.*)top(.*) $1top_display_media$2 [NC]
#
# Rewrite usrmgr urls
#
RewriteRule usermgr-page-([0-9]*).html(.*) usermgr.php?page=$1$2 [NC]
RewriteRule usermgr.html(.*) usermgr.php$1 [NC]
#
# Rewrite index urls
#
RewriteRule index.html(.*) index.php$1 [NC]
RewriteRule index-([0-9]*)\.html(.*) index.php?cat=$1$2 [NC]
RewriteRule index-([0-9]*)-page-([0-9]*)\.html(.*) index.php?cat=$1&page=$2$3 [NC]
#
# Rewrite thumbnail urls
#
RewriteRule thumbnails-lastupby-([0-9]+)\.html(.*) thumbnails.php?album=lastupby&uid=$1$2 [NC]
RewriteRule thumbnails-lastcomby-([0-9]+)\.html(.*) thumbnails.php?album=lastcomby&uid=$1$2 [NC]
RewriteRule thumbnails-lastupby-([0-9]+)-([0-9]+)-page-([0-9]+)\.html(.*) thumbnails.php?album=lastupby&cat=$1&uid=$2&page=$3$4 [NC]
RewriteRule thumbnails-lastcomby-([0-9]+)-([0-9]+)-page-([0-9]+)\.html(.*) thumbnails.php?album=lastcomby&cat=$1&uid=$2&page=$3$4 [NC]
RewriteRule thumbnails-([a-z0-9]*)-([\-]?[0-9]*)\.html(.*) thumbnails.php?album=$1&cat=$2$3 [NC]
RewriteRule thumbnails-page-([0-9]*)-([a-z0-9]*).*\.html(.*) thumbnails.php?album=$2&page=$1$3 [NC]
RewriteRule thumbnails-([a-z0-9]*)-([\-]?[0-9]*)-page-([0-9]*)\.html(.*) thumbnails.php?album=$1&cat=$2&page=$3$4 [NC]
RewriteRule thumbnails-search-keyword-(.*)\.html(.*) thumbnails.php?album=search&keywords=on&search=$1$2 [NC]
RewriteRule thumbnails-search-(.*)\.html(.*) thumbnails.php?album=search&search=$1$2 [NC]
RewriteRule thumbnails-([0-9a-z]*).*\.html(.*) thumbnails.php?album=$1$2 [NC]
#
# Rewrite displayimage urls
#
RewriteRule displayimage-lastcom-([\-]?[0-9]+)-([\-]?[0-9]+)-([\-]?[0-9]+)-page-([\-]?[0-9]+).html(.*) displayimage.php?album=lastcom&cat=$1&pid=$2&msg_id=$3&page=$4$5 [NC]
RewriteRule displayimage-([a-z0-9]+)-([\-]?[0-9]+)-([\-]?[0-9]+)-([\-]?[0-9]+)-([\-]?[0-9]+)-([\-]?[0-9]+)\.html(.*) displayimage.php?album=$1&cat=$2&pid=$3&uid=$4&msg_id=$5&page=$6$7 [NC]
RewriteRule displayimage-([a-z0-9]+)-([\-]?[0-9]+)-([\-]?[0-9]+)-([\-]?[0-9]+)\.html(.*) displayimage.php?album=$1&cat=$2&pid=$3&uid=$4$5 [NC]
RewriteRule displayimage-([a-z0-9]+)-([\-]?[0-9]+)-([\-]?[0-9]+).*\.html(.*) displayimage.php?album=$1&cat=$2&pid=$3$4 [NC]
RewriteRule displayimage-([a-z0-9]+)-([\-]?[0-9]+).*\.html(.*) displayimage.php?album=$1&pid=$2$3 [NC]
RewriteRule displayimage-([0-9]+).*\.html(.*) displayimage.php?pid=$1$2 [NC]
#
# Rewrite users profiles
#
RewriteRule profile-op-([a-z0-9_]+)\.html(.*) profile.php?op=$1 [NC]
RewriteRule profile-([0-9]+).*\.html(.*) profile.php?uid=$1$2 [NC]
I'm sure I'm missing something, but unfortunately I have no clue.
Any hints?
According to that AhrefBot's link, this is all you need to do to stop that particular bot:
user-agent: AhrefsBot
disallow: /
By adding the above to a robots.txt file in your document root.
The other thing is this:
order allow,deny
Is in the wrong order. According to apache's mod_access documentation:
Allow,Deny
First, all Allow directives are evaluated; at least one must match, or the request is rejected. Next, all Deny directives are evaluated. If any matches, the request is rejected. Last, any requests which do not match an Allow or a Deny directive are denied by default.
Because you have "Allow from all", it gets evaluated first and the different "Deny"'s never get evaluated. So you want:
Order Deny,Allow

htaccess permanent redirect from file that doesn't exists anymore

I got an old Peel shop that I moved on Prestashop. Before switch it live, I would like to keep the Google ranks I got on some products (approximatly 100 products).
So far I make my tests on Prestashop pre-prod server, with a domain name like "mywebsite.com/~subfolder/" (forced by hosting company). All products have been imported from Peel to Prestashop.
I thought that a simple
Options +FollowSymlinks
RewriteEngine on
RedirectPermanent /~subfolder/achat/product_detail.php?id=300 http://www.mywebsite.com/~subfolder/my/new/url-300.html
would worked, but I'm always redirected to the Prestashop not found page. As far as I see, it doesn't accept the fact that "achat/product_detail.php" does not exist.
I also tried
RewriteRule ^/~subfolder/achat/produit_details.php?id=110$ /~subfolder/layette-en-laine-et-soie/110-brassiere-laine-et-soie.html [L,R=301]
which is not working better.
What is the correct way to handle this? If possible in a relative way meaning that I would prefer not to have to modify the file when I will switch Prestashop live (and change http://mywebsite.com/~subfolder to http://www.mywebsite.com).
Any help would be greatly appreciated !
Thanks,
Nicolas
PS : if needed, below my htaccess file generated by prestashop (I removed the tests mentionned above) :
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# WARNING: PLEASE DO NOT MODIFY THIS FILE MANUALLY. IF NECESSARY, ADD YOUR SPECIFIC CONFIGURATION WITH THE HTACCESS GENERATOR IN BACK OFFICE
# http://www.prestashop.com - http://www.prestashop.com/forums
SetEnv PHP_VER 5_TEST
SetEnv REGISTER_GLOBALS 0
AuthUserFile /XXXX
AuthGroupFile /dev/null
AuthName "Veuillez vous identifier"
AuthType Basic
require valid-user
<IfModule mod_rewrite.c>
# URL rewriting module activation
RewriteEngine on
# URL rewriting rules
RewriteRule ^api/?(.*)$ /~subfolder/webservice/dispatcher.php?url=$1 [QSA,L]
RewriteRule ^([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1-$2$3.jpg [L]
RewriteRule ^([0-9]+)\-([0-9]+)/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1-$2.jpg [L]
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$1$2.jpg [L]
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$2/$1$2$3.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$2/$3/$1$2$3$4.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^c/([0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/c/$1$2.jpg [L]
RewriteRule ^c/([a-zA-Z-]+)/[a-zA-Z0-9-]+\.jpg$ /~subfolder/img/c/$1.jpg [L]
RewriteRule ^([0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$ /~subfolder/img/c/$1$2.jpg [L]
RewriteRule ^([0-9]+)\-[a-zA-Z0-9-]*\.html /~subfolder/product.php?id_product=$1 [QSA,L]
RewriteRule ^[a-zA-Z0-9-]*/([0-9]+)\-[a-zA-Z0-9-]*\.html /~subfolder/product.php?id_product=$1 [QSA,L]
RewriteRule ^([0-9]+)\-[a-zA-Z0-9-]*(/[a-zA-Z0-9-]*)+ /~subfolder/category.php?id_category=$1&noredirect=1 [QSA,L]
RewriteRule ^([0-9]+)\-[a-zA-Z0-9-]* /~subfolder/category.php?id_category=$1 [QSA,L]
RewriteRule ^([0-9]+)__([a-zA-Z0-9-]*) /~subfolder/supplier.php?id_supplier=$1 [QSA,L]
RewriteRule ^([0-9]+)_([a-zA-Z0-9-]*) /~subfolder/manufacturer.php?id_manufacturer=$1 [QSA,L]
RewriteRule ^content/([0-9]+)\-([a-zA-Z0-9-]*) /~subfolder/cms.php?id_cms=$1 [QSA,L]
RewriteRule ^content/category/([0-9]+)\-([a-zA-Z0-9-]*) /~subfolder/cms.php?id_cms_category=$1 [QSA,L]
RewriteRule ^page-non-trouvee$ /~subfolder/404.php [QSA,L]
RewriteRule ^adresse$ /~subfolder/address.php [QSA,L]
RewriteRule ^adresses$ /~subfolder/addresses.php [QSA,L]
RewriteRule ^authentification$ /~subfolder/authentication.php [QSA,L]
RewriteRule ^meilleures-ventes$ /~subfolder/best-sales.php [QSA,L]
RewriteRule ^panier$ /~subfolder/cart.php [QSA,L]
RewriteRule ^contactez-nous$ /~subfolder/contact-form.php [QSA,L]
RewriteRule ^bons-de-reduction$ /~subfolder/discount.php [QSA,L]
RewriteRule ^suivi-commande-invite$ /~subfolder/guest-tracking.php [QSA,L]
RewriteRule ^historique-des-commandes$ /~subfolder/history.php [QSA,L]
RewriteRule ^identite$ /~subfolder/identity.php [QSA,L]
RewriteRule ^fabricants$ /~subfolder/manufacturer.php [QSA,L]
RewriteRule ^mon-compte$ /~subfolder/my-account.php [QSA,L]
RewriteRule ^nouveaux-produits$ /~subfolder/new-products.php [QSA,L]
RewriteRule ^commande$ /~subfolder/order.php [QSA,L]
RewriteRule ^details-de-la-commande$ /~subfolder/order-follow.php [QSA,L]
RewriteRule ^commande-rapide$ /~subfolder/order-opc.php [QSA,L]
RewriteRule ^avoirs$ /~subfolder/order-slip.php [QSA,L]
RewriteRule ^mot-de-passe-oublie$ /~subfolder/password.php [QSA,L]
RewriteRule ^promotions$ /~subfolder/prices-drop.php [QSA,L]
RewriteRule ^recherche$ /~subfolder/search.php [QSA,L]
RewriteRule ^plan-du-site$ /~subfolder/sitemap.php [QSA,L]
RewriteRule ^magasins$ /~subfolder/stores.php [QSA,L]
RewriteRule ^fournisseurs$ /~subfolder/supplier.php [QSA,L]
</IfModule>
# Catch 404 errors
ErrorDocument 404 /~subfolder/404.php
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 year"
</IfModule>
FileETag INode MTime Size
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
You cannot match against the query string using a RewriteRule and you cannot include query strings in the Redirect directives. You need to use a RewriteCond for the query string:
RewriteCond %{QUERY_STRING} ^id=110$
RewriteRule ^~subfolder/achat/produit_details.php$ /~subfolder/layette-en-laine-et-soie/110-brassiere-laine-et-soie.html [L,R=301]
Note that you also need to remove the leading / in the match because it gets stripped by the rewrite engine within the .htaccess file.
I finally answer my question : in case detailled above, the solution to have a valid redirection is below :
RewriteCond %{QUERY_STRING} ^id=110$
RewriteRule ^achat/produit_details.php$ /~subfolder/layette-en-laine-et-soie/110-brassiere-laine-et-soie.html [L,R=301]
To be done for each product id that need a redirection
Hope it will help !

Resources