I am trying to combine two .htaccess files into one:
https://github.com/silverstripe/silverstripe-installer/blob/3.1/.htaccess
AND
https://github.com/jkphl/squeezr/blob/master/.htaccess
I also want to exclude the CMS from any squeezr rules (i.e. links to http://www.mysite.co.nz/admin/.... should not run via squeezr.
Is it sufficient to basically combine the two .htaccess files and write the final redirection rule for silverstripe as follows:
RewriteRule (?!^squeezr|admin)^.*$ framework/main.php?url=$1 [L,QSA,NC]
Please let me know if you need more information in this question and I will add.
You should be able to just combine the 2. There doesn't seem any conflict
https://gist.github.com/24b48c12d82c73e60a37
EDIT:
In your question you also mention that you want to exclude the cms from sqeezer, the idea makes sense, however, the RewriteRule you have posted does not at all, in fact I would be surprised if that did not throw an error.
The only thing the above rule would do (if it would work), would be to exclude squeezr files from being rewritten to framework, but that would never happen anyway, because the RewriteConds before would already deny that (SilverStripe does not rewrite existing files).
so what you need to do is actually add a RewriteCond to the 2 squeezr rules, to tell them not to use cms and framework.
I believe adding the 2 following conditions (right before the squeezr rules) would do that:
RewriteCond %{REQUEST_URI} !cms # exclude the silverstripe cms
RewriteCond %{REQUEST_URI} !framework # exclude the silverstripe framework which is by
(you can also view it as diff for the gist here: https://gist.github.com/Zauberfisch/d681474df67ced83ec1f/revisions)
the full config file:
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files web.config>
Order deny,allow
Deny from all
</Files>
<Files ~ "\.ya?ml$">
Order allow,deny
Deny from all
</Files>
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Start the rewrite engine
RewriteEngine On
RewriteBase /
# REDIRECT ANY DIRECT IMAGE REQUEST TO A CACHED VERSION
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{ENV:REDIRECT_BREAKPOINT} !\d+px
RewriteCond %{QUERY_STRING} !^([^&]*&)*squeezr=(0|false|no)
RewriteCond %{HTTP_COOKIE} squeezr.images=(\d+px) [NC]
RewriteCond %{REQUEST_URI} !cms # exclude the silverstripe cms
RewriteCond %{REQUEST_URI} !framework # exclude the silverstripe framework which is by the cms
RewriteRule ^(.+)(\.(?:jpe?g|gif|png))$ squeezr/cache/$1-%1$2 [NC,E=BREAKPOINT:%1,L]
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Please make sure that you set this path ^^^ to the squeezr root directory that is also specified
# for the SQUEEZR_ROOT constant in the common engine configuration (SQUEEZR_ROOT/conf/common.php). If you
# apply the default setup for squeezr (i.e. put everything into a directory named "squeezr" under your
# website's document root), then you shouldn't have to change anything.
#############################################################################################################
# REDIRECT ANY DIRECT CSS REQUEST TO A CACHED VERSION
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{ENV:REDIRECT_BREAKPOINT} !\d+px
RewriteCond %{QUERY_STRING} !^([^&]*&)*squeezr=(0|false|no)
RewriteCond %{HTTP_COOKIE} squeezr.css=(\d+x\d+#\d+(?:\.\d+)?) [NC]
RewriteCond %{REQUEST_URI} !cms # exclude the silverstripe cms
RewriteCond %{REQUEST_URI} !framework # exclude the silverstripe framework which is by the cms
RewriteRule ^(.+)\.css$ squeezr/cache/$1-%1.css [NC,E=BREAKPOINT:%1,L]
# ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# See above for hints on ^^^ this path.
#############################################################################################################
### SILVERSTRIPE START ###
RewriteRule ^vendor(/|$) - [F,L,NC]
RewriteRule silverstripe-cache(/|$) - [F,L,NC]
RewriteRule composer\.(json|lock) - [F,L,NC]
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule .* framework/main.php?url=%1 [QSA]
RewriteCond %{REQUEST_URI} ^(.*)/framework/main.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . %1/install.php? [R,L]
### SILVERSTRIPE END ###
</IfModule>
#############################################################################################################
# Additional stuff for improving your website's delivery performance
#############################################################################################################
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css text/javascript text/json text/x-json text/x-json-stream application/x-javascript application/json application/x-json application/x-json-stream application/.*xml.* multipart/x-json-stream multipart/x-mixed-replace image/svg+xml
</IfModule>
<IfModule mod_expires.c>
ExpiresActive on
# Images
ExpiresByType image/gif "access plus 35 days"
ExpiresByType image/png "access plus 35 days"
ExpiresByType image/jpg "access plus 35 days"
ExpiresByType image/jpeg "access plus 35 days"
# Text based files
ExpiresByType text/css "access plus 35 days"
ExpiresByType text/xml "access plus 35 days"
ExpiresByType text/javascript "access plus 35 days"
ExpiresByType application/x-shockwave-flash "access plus 35 days"
# Default expiration
ExpiresDefault "access plus 1 days"
</IfModule>
Related
I've got a Silverstripe installation on let's say www.silverstripe.com. Now in the root folder, I uploaded a custom map/files. Let's say I uploaded a Wordpress install to www.silverstripe.com/wordpress.
I need the Wordpress install to be accessible on www.silverstripe.com/wordpress, and usually that will work. But because of the .htaccess, the url returns a blank Silverstripe page and redirects to https://www.silverstripe.com/wordpress/?url=/wordpress.
How to get it to work? This is my current .htaccess:
# Deny access to templates (but allow from localhost)
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
# Deny access to IIS configuration
<Files web.config>
Order deny,allow
Deny from all
</Files>
# Deny access to YAML configuration files which might include sensitive information
<Files *.yml>
Order allow,deny
Deny from all
</Files>
# Route errors to static pages automatically generated by SilverStripe
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html
<IfModule mod_rewrite.c>
# Turn off index.php handling requests to the homepage fixes issue in apache >=2.4
<IfModule mod_dir.c>
DirectoryIndex disabled
</IfModule>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
# Redirect non www to www
RewriteCond %{HTTP_HOST} ^silverstripe.com$ [NC]
RewriteRule (.*) http://www.silverstripe.com/$1 [R=301,L]
# Redirect non https to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Deny access to .git files and folders
RedirectMatch 404 /\.git
# Deny access to potentially sensitive files and folders
RewriteRule ^vendor(/|$) - [F,L,NC]
RewriteRule silverstripe-cache(/|$) - [F,L,NC]
RewriteRule composer\.(json|lock) - [F,L,NC]
# Process through SilverStripe if no file with the requested name exists.
# Pass through the original path as a query parameter, and retain the existing parameters.
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* framework/main.php?url=%1 [QSA]
</IfModule>
### SILVERSTRIPE END ###
# No access to .less files
<Files *.less>
Order allow,deny
Deny from all
</Files>
# Custom caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 5 minutes"
ExpiresByType image/gif "access plus 7 day"
ExpiresByType image/png "access plus 7 day"
ExpiresByType image/jpg "access plus 7 day"
ExpiresByType image/jpeg "access plus 7 day"
ExpiresByType image/ico "access plus 7 day"
ExpiresByType text/css "access plus 7 day"
ExpiresByType text/javascript "access plus 7 day"
ExpiresByType application/x-javascript "access plus 7 day"
</IfModule> ```
Is there any way to Redirect a page from one page to another page without changing the URL using htaccess in joomla?
I want to load URL site.com/page1 load content site.com/page2. I tried to do this with the following command:
RewriteRule ^page1$ /page2 [L]
Or
RewriteRule ^page1$ /page2
But nothing has changed.
When it tried to do not Joomla then works fine
Is there any way to Redirect a page from one page to another page without changing the URL using htaccess in joomla?
I want to load URL site.com/page1 load content site.com/page2. I tried to do this with the following command:
RewriteRule ^page1$ /page2 [L]
Or
RewriteRule ^page1$ /page2
But nothing has changed.
When it tried to do not Joomla then works fine.
here is my htaccess file
##
# #package Joomla
# #copyright Copyright (C) 2005 - 2014 Open Source Matters. All rights reserved.
# #license GNU General Public License version 2 or later; see LICENSE.txt
##
##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's. If they work,
# it has been set by your server administrator and you do not need it set here.
##
## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks
## Mod_rewrite in use.
RewriteEngine On
## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.
## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects
##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##
RewriteBase /
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} !^/administrator
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ / [R=301,L]
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L]
RewriteRule ^page1$ /page2 [L]
## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
RewriteCond %{REQUEST_URI} ^/sitemap.xml
RewriteRule .* /index.php?option=com_xmap&id=1&view=xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access 7 days"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
ExpiresByType text/css "access plus 1 year"
ExpiresByType text/html "access plus 7 day"
ExpiresByType text/x-javascript "access 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/x-shockwave-flash "access 1 year"
</IfModule>
You can do it as follows
RewriteEngine on
RewriteRule ^(page2)$ /page1 [L]
Also you mention Joomla!, so It already has as RewriteEngine on, then just insert the following code right below it, before the Joomla!'s own rewrite rules kick in.
RewriteRule ^(page2)$ /page1 [L]
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!
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]
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 !