mod_rewrite directives work on their own but not in context of full htaccess file with concrete5 - apache

I am having trouble ammending a site's htaccess file with some mod_rewrite directives I know work in isolation but not in context of the full htaccess file. The site's CMS is Concrete5, so there are some specifics for the Concrete5 configuration in the htaccess file.
I am trying to rewrite URLS of format
http://www.mywebsite.com/proplist/?location=town&distance=3&proptype=buy&maxPrice=&minPrice=&bedrooms=&propertyType=
to
http://www.mywebsite.com/property/town/buy/
I have got the following directives to work in isolation (where I created index.php in a folder called proplist under the webroot on another webserver):
RewriteBase /proplist
RewriteRule property/([a-zA-z]+)/([a-zA-z]+)/$ http://www.mywebsite.com/property/\/?location=$1&distance=3&proptype=$2&maxPrice=&minPrice=&bedrooms=&propertyType= [R]
Redirect 301 /property/ http://www.mywebsite.com/proplist/
(I guess I can use %{REQUEST_FILENAME} instead of http://www.mywebsite.com)
I can't get the above to work in the context of the htaccess file that is already in place which is (with my ammendments):
<IfModule mod_rewrite.c>
RewriteEngine On
#
# -- concrete5 urls start --
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
# -- concrete5 urls end --
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# -- rewrite property search urls --
RewriteBase /proplist
RewriteCond %{REQUEST_URI} property
RewriteRule property/([a-zA-z]+)/([a-zA-z]+)/$ http://www.mywebsite.com/proplist/\/?location=$1&distance=3&proptype=$2&maxPrice=&minPrice=&bedrooms=&propertyType= [R]
Redirect 301 /property/ %{REQUEST_FILENAME}/proplist/
RewriteBase /
# -- end rewrite property search urls --
#Gzip
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript
</ifmodule>
#End Gzip
# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 1 week"
</IfModule>
## EXPIRES CACHING ##
AddType application/font-wof .woff
AddType application/x-font-woff .woff
AddType application/x-woff .woff
# end of full htaccess file
The result of the above is urls such as http://www.mywebsite.com/property/woking/buy/ being redirected to http://www.mywebsite.com/index.php
Can anyone help?

The first thing you need to do is place all the property search URL rules before the concrete5 routing rules. The routing rules completely mangle the URI and when a redirect happens, the mangled URI ends up getting redirected.
So that means these rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
must be before your CMS rules.
You also probably want to change your rules from:
# -- rewrite property search urls --
RewriteBase /proplist
RewriteCond %{REQUEST_URI} property
RewriteRule property/([a-zA-z]+)/([a-zA-z]+)/$ http://www.mywebsite.com/proplist/\/?location=$1&distance=3&proptype=$2&maxPrice=&minPrice=&bedrooms=&propertyType= [R]
Redirect 301 /property/ %{REQUEST_FILENAME}/proplist/
RewriteBase /
# -- end rewrite property search urls --
to:
# -- rewrite property search urls --
RewriteRule ^property/([a-zA-z]+)/([a-zA-z]+)/$ /proplist/?location=$1&distance=3&proptype=$2&maxPrice=&minPrice=&bedrooms=&propertyType= [L]
RewriteRule ^property/$ /proplist/ [L]
# -- end rewrite property search urls --
But I'm not really sure what the point of your original rules were. They're a mix of mod_alias and mod_rewrite which was sure to be a mess. Change the flags from [L] to [L,R=301] if you actually wanted to redirect instead of rewriting (which is what you are asking for, rewriting is not redirecting). So those 2 rules need to go right below the one that redirects to www.

Related

Error ModRewrite in htaccess. URL 404 Error

I want to force .php extension from htaccess, because someone changed it and now all my URLs give 404 error. Can somebody help me? If you wanna I can publish the .htaccess. I've also tried Mike solution, but everything stays without .php extension and 404 error.
Also i tried to modify it from the PHP archives but the same error appears.
# It is required for use of mod_rewrite, but may already be set by your server administrator in a way that dissallows ...
Options +FollowSymLinks
Options -MultiViews
# Redirect to .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [R=301,L]
# Mod_rewrite in use.
RewriteEngine On
# Mod_rewrite in use.
RewriteEngine On
# SEGUIMOS
Redirect 301 /si-no-queda-satisfecho-le-devolvemos-el-dinero.html https://www.academiapinto.es/otros-enlaces/si-no-queda-satisfecho-le-devolvemos-el-dinero.php
Redirect 301 /si-no-queda-satisfecho-le-devolvemos-el-dinero.php https://www.academiapinto.es/otros-enlaces/si-no-queda-satisfecho-le-devolvemos-el-dinero.php
# Redirect 301 / https://www.academiapinto.es/
#parche POLILLA
Redirect 301 /temario-Guardias-Jovenes-(Polillas).php https://www.academiapinto.es/oposiciones-de-ingreso-Colegio-Guardias-Jovenes-Duque-de-Ahumada.php
Redirect 301 /blog-academia-pinto-para-preparar-tus-oposiciones-para-la-PN.php https://www.academiapinto.es/blog/articulo-academia-pinto-para-preparar-tus-oposiciones-para-la-PN.php
Redirect 301 /blog-camino-a-baeza.php https://www.academiapinto.es/blog/articulo-camino-a-baeza.php
Redirect 301 /blog-como-seleccionar-una-buena-academia-de-oposiciones-para-guardia-civil-y-policia-nacional.php https://www.academiapinto.es/blog/articulo-como-seleccionar-una-buena-academia-de-oposiciones-para-guardia-civil-y-policia-nacional.php
Redirect 301 /blog-dime-como-estudias.php https://www.academiapinto.es/blog/articulo-dime-como-estudias.php
Redirect 301 /blog-documentacion-instancia-oposicion-ingreso-a-la-guardia-civil.php https://www.academiapinto.es/blog/articulo-documentacion-instancia-oposicion-ingreso-a-la-guardia-civil.php
Redirect 301 /blog-llego-la-hora.php https://www.academiapinto.es/blog/articulo-llego-la-hora.php
Redirect 301 /blog-primer-concurso-de-fotografia.php https://www.academiapinto.es/blog/articulo-primer-concurso-de-fotografia.php
Redirect 301 /blog-psicotecnicos-recomendaciones-necesarias.php https://www.academiapinto.es/blog/articulo-psicotecnicos-recomendaciones-necesarias.php
Redirect 301 /blog-que-no-puedes-olvidar-en-tu-examen-para-la-guardia-civil.php https://www.academiapinto.es/blog/articulo-que-no-puedes-olvidar-en-tu-examen-para-la-guardia-civil.php
Redirect 301 /blog-tecnicas-de-estudio-para-aprobar-las-oposiciones-de-gc.php https://www.academiapinto.es/blog/articulo-tecnicas-de-estudio-para-aprobar-las-oposiciones-de-gc.php
Redirect 301 /blog-tienes-la-documentacion.php https://www.academiapinto.es/blog/articulo-tienes-la-documentacion.php
Redirect 301 /noticia-Academia-Pinto-incrementa-las-horas-de-clases-online.php https://www.academiapinto.es/news/noticia-Academia-Pinto-incrementa-las-horas-de-clases-online.php
Redirect 301 /noticia-instrucciones-rellenar-instancia-ingreso-guardia-civil.php https://www.academiapinto.es/news/noticia-instrucciones-rellenar-instancia-ingreso-guardia-civil.php
Redirect 301 /noticia-oferta-curso-online-ingreso-Guardia-Civil.php https://www.academiapinto.es/news/noticia-oferta-curso-online-ingreso-Guardia-Civil.php
# las de los empleos
Redirect 301 /curso-a-distancia-ingreso-guardia-civil https://www.academiapinto.es/temario-de-ingreso-guardia-civil.php
Redirect 301 /curso-a-distancia-ingreso-policia-nacional-escala-basica.php https://www.academiapinto.es/temario-de-ingreso-a-policia-nacional-escala-basica.php
Redirect 301 /curso-a-distancia-cabo-guardia-civil.php https://www.academiapinto.es/temario-de-ascenso-a-cabo-guardia-civil.php
Redirect 301 /curso-a-distancia-cabosub-guardia-civil.php https://www.academiapinto.es/temario-de-ascenso-a-cabo-guardia-civil.php
Redirect 301 /curso-a-distancia-suboficial-guardia-civil.php https://www.academiapinto.es/temario-de-ascenso-a-suboficial-guardia-civil.php
Redirect 301 /curso-a-distancia-oficial-guardia-civil.php https://www.academiapinto.es/temario-de-ascenso-a-oficial-guardia-civil.php
# antiguas de JUAN arregladas
# ahora cambiamos por las mejoras SEO las siguientes.
Redirect 301 /clases-presenciales-de-ingreso-guardia-civil.php https://www.academiapinto.es/curso-de-ingreso-a-guardia-civil.php
Redirect 301 /clases-online-de-ingreso-guardia-civil.php https://www.academiapinto.es/curso-online-de-ingreso-a-guardia-civil.php
Redirect 301 /clases-online-de-cabo-guardia-civil.php https://www.academiapinto.es/curso-online-de-ascenso-a-cabo-guardia-civil.php
Redirect 301 /curso-online-de-cabo-guardia-civil.php https://www.academiapinto.es/curso-online-de-ascenso-a-cabo-guardia-civil.php
# seguimos.
Redirect 301 /clases-online-de-oficial-guardia-civil.php https://www.academiapinto.es/curso-online-de-ascenso-a-oficial-guardia-civil.php
Redirect 301 /clases-online-de-suboficial-guardia-civil.php https://www.academiapinto.es/curso-online-de-ascenso-a-suboficial-guardia-civil.php
Redirect 301 /clases-presenciales-de-ascenso-a-oficial-guardia-civil.php https://www.academiapinto.es/curso-de-ascenso-a-oficial-guardia-civil.php
Redirect 301 /clases-presenciales-de-ascenso-a-suboficial-guardia-civil.php https://www.academiapinto.es/curso-de-ascenso-a-suboficial-guardia-civil.php
Redirect 301 /temario-Prueba-Conocimientos-Guardias-Jovenes-(Polillas).php https://www.academiapinto.es/temario-Guardias-Jovenes-(Polillas).php
#parche NO-CNP
Redirect 301 /curso-a-distancia-guardia-civil-y-policia-nacional.php https://www.academiapinto.es/curso-online-de-ingreso-a-guardia-civil.php
Redirect 301 /temario-Guardias-Jovenes-(Polillas).php https://www.academiapinto.es/temario-Guardias-Jovenes-(Polillas).php
# using root, not index.php ...
# RewriteRule ^index\.php$ https://www.academiapinto.es/ [L,R=301]
# RewriteRule ^index\.htm$ https://www.academiapinto.es/ [L,R=301]
# RewriteRule ^index\.html$ https://www.academiapinto.es/ [L,R=301]
RewriteRule ^/temario-de-ingreso-guardia-civil$ https://www.academiapinto.es/temario-de-ingreso-guardia-civil.php [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
# ... seguridades varias que interesan ...
# 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]
# ... check for parameters ...
# RewriteRule ^([A-Za-z0-9_]+)/([A-Za-z0-9_]+)/([A-Za-z0-9_]+)/([A-Za-z0-9_]+)$ /index.php [L]
# RewriteRule ^([A-Za-z0-9_]+)/([A-Za-z0-9_]+)/([A-Za-z0-9_]+)$ /index.php [L]
# RewriteRule ^([A-Za-z0-9_]+)/([A-Za-z0-9_]+)$ /index.php [L]
# RewriteRule ^([A-Za-z0-9_]+)$ /index.php [L]
# --- #RewriteRule ^(.*) /index.php?p1=ERROR_MODRW_ACCESS [L]
##############################################################
# Enable GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css 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>
# Expires Headers - 2678400s = 31 days
<ifmodule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 7200 seconds"
ExpiresByType image/gif "access plus 2678400 seconds"
ExpiresByType image/jpeg "access plus 2678400 seconds"
ExpiresByType image/png "access plus 2678400 seconds"
ExpiresByType text/css "access plus 518400 seconds"
ExpiresByType text/javascript "access plus 2678400 seconds"
ExpiresByType application/x-javascript "access plus 2678400 seconds"
</ifmodule>
# Cache Headers
<ifmodule mod_headers.c>
# Cache specified files for 31 days 2678400
<filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
Header set Cache-Control "max-age=2678400, public"
</filesmatch>
# Cache HTML files for a couple hours 7200
<filesmatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, private, must-revalidate"
</filesmatch>
# Cache PDFs for a day 86400
<filesmatch "\.(pdf)$">
Header set Cache-Control "max-age=86400, public"
</filesmatch>
# Cache Javascripts for 31 days 2678400
<filesmatch "\.(js)$">
Header set Cache-Control "max-age=2678400, private"
</filesmatch>
</ifmodule>
##############################################################
Thanks, i'm really desperated with this one.

htaccess for new image folder

I'm trying to rewrite the url to another url.
because i already made a subdomain for my images and i want all the url requesting for my images should get in the new image domain.
for example.
old image link - http://www.website.com/uploaded/art/sd.jpg
should get to - http://img.website.com/uploaded/art/sd.jpg
another one
old image link - http://www.website.com/uploaded/photo/ss.jpg
should get to - http://img.website.com/uploaded/photo/ss.jpg
i have my subfolders in my uploaded folder.
here is my htaccess for now and it seems i cant get it to work.
RewriteEngine on
RewriteRule ^uploaded/(.*)$ http://img.website.com/uploaded/$1 [R=301,L]
# Use PHP5.4 as default
#AddHandler application/x-httpd-php54 .php
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L,NC]
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 day"
ExpiresByType text/css "access plus 18000 seconds"
ExpiresByType text/plain "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 18000 seconds"
ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
this htaccess is saved to my public html folder. main root of my website.
Create an htaccess in the /uploaded folder and add the following redirect :
Redirect 302 /uploaded/ http://img.website.com/uploaded/
This will redirect all requests from /uploaded folder to the new destination, eg : example.com/uploaded/foobar to http://img.website.com/uploaded/foobar .
You change the redirect status to 301 (permanent redirect) when you are sure it's working ok.

How do I create an exception for my htaccess setting that enables friendly URLs?

I have a LAMP server, but I do more website coding and design than Apache configuration. I hope my question will be clear because I don't understand the syntax of .htaccess files very well, and the code I have is mostly derived from tutorials on the web.
My website uses "friendly URLs", and to enable that function, I have the following code in my .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
However, I've created a subdirectory with a whole different set of HTML under a subdirectory that I want to be able to access by going to a URL like this: http://www.example.com/subdirectory.
What is happening is that even if I go directly to http://www.example.com/subdirectory/index.html, Apache still redirects to index.php in the root.
Is there a way I can modify my .htaccess file so that my subdirectory will be exempted from the redirection?
UPDATE:
After some experimenting, I've determined that it is exactly this line that is causing the problem (which may be obvious to people more skilled than I am with .htaccess files):
RewriteRule ^(.*) index.php
If I comment that line out, everything in the subdirectory works fine (the rest of the site, of course, breaks). If I leave it in, I get the problem described above.
As suggested in an answer below, I tried changing the line to:
RewriteRule !^subdirectory index.php
But that didn't fix the problem. I also tried making a .htaccess file in the subdirectory with these contents:
RewriteEngine On
Unfortunately, that did nothing.
My limited understanding of .htaccess syntax says that the line I already have should leave the contents of my subdirectory alone, but it is acting far more aggressively than intended.
Is there a way I can diagnose and fix this line so that it does not act upon the contents of my subdirectory?
UPDATE 2:
After some experimentation, I found that the .htaccess file in the subdirectory is not being read. If I put gibberish text in it, I don't get any errors, which seems to indicate it's not even being accessed.
I looked for reasons why my .htaccess file might not be being read, and I found that in my .conf file for the site, I need to have this code:
AllowOverride All
I have that directive in there, but the .htaccess in the subdirectory is still not being read.
What to I do to ensure the .htaccess file in the subdirectory is being read?
Contents of my root .htaccess file:
# BEGIN Compress text files
<IfModule mod_deflate.c>
<FilesMatch "\.(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
# END Compress text files
# BEGIN Expire headers
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 2592000 seconds"
ExpiresByType application/javascript "access plus 2592000 seconds"
ExpiresByType application/x-javascript "access plus 2592000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</IfModule>
# END Expire headers
# BEGIN Cache-Control Headers
<IfModule mod_headers.c>
<FilesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
<FilesMatch "\.(css)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\.(js)$">
Header set Cache-Control "max-age=216000, private"
</FilesMatch>
<FilesMatch "\.(x?html?|php)$">
Header set Cache-Control "max-age=600, private, must-revalidate"
</FilesMatch>
</IfModule>
# END Cache-Control Headers
# BEGIN Turn ETags Off
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
FileETag None
# END Turn ETags Off
# BEGIN Remove Last-Modified Header
<IfModule mod_headers.c>
Header unset Last-Modified
</IfModule>
# END Remove Last-Modified Header
# Make all requests pass through index.php to enable "friendly URLs"
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
# Turn off 'magic quotes'
php_value magic_quotes_gpc off
# Do not allow Perl script hackers, as they are probably just feeding useless Adsense "directory" sites
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* - [F,L]
# Filter for most common exploits
RewriteCond %{HTTP_USER_AGENT} libwww-perl [OR]
RewriteCond %{QUERY_STRING} tool25 [OR]
RewriteCond %{QUERY_STRING} cmd.txt [OR]
RewriteCond %{QUERY_STRING} cmd.gif [OR]
RewriteCond %{QUERY_STRING} r57shell [OR]
RewriteCond %{QUERY_STRING} c99 [OR]
# deny most common except .php
<FilesMatch "\.(inc|tpl|h|ihtml|sql|ini|conf|class|bin|spd|theme|module)$">
deny from all
</FilesMatch>
# Disable .htaccess viewing from browser
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</Files>
This code is in my /etc/apche2/apache2.conf:
# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess
... and here is the contents of the conf file specific to the site in question:
<VirtualHost *:80>
ServerName www.local_example.com
ServerAlias local_example.com
ServerAdmin serveradmin#gmail.com
DocumentRoot /var/www/example.com
<Directory /var/www/example.com/>
Options Indexes FollowSymLinks MultiViews
# pcw AllowOverride None
AllowOverride All
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
# Commented out for Ubuntu
#RedirectMatch ^/$ /apache2-default/
</Directory>
ErrorLog /home/admin/Apache_Logs/local_example.com_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog /home/admin/Apache_Logs/local_example.com_access.log combined
ServerSignature On
</VirtualHost>
If /subdirectory is a physical directory on the filesystem and /subdirectory/index.html is an actual file then your current directives already include the necessary exception... the URL should not be rewritten if the requested URL maps to a physical directory or file.
However, to explicitly include an exception for the /subdirectory then you could do something like:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !^subdirectory index.php
Only URLs that do not start /subdirectory will be processed. (Not that the directory-prefix is removed when matching the URL-path with the RewriteRule pattern, so it should be subdirectory here, not /subdirectory.)
Alternatively, you can create an additional .htaccess at /subdirectory/.htaccess and simply enable the rewrite engine:
# /subdirectory/.htaccess
RewriteEngine On
mod_rewrite directives are not inherited by default, so this should completely override the mod_rewrite directives in the parent .htaccess file. (Note that other directives from different modules might still be processed.)
UPDATE: I cannot see anything in your .htaccess file that would directly cause these symptoms, however, the following does need fixing/tidying...
# Do not allow Perl script hackers, as they are probably just feeding useless Adsense "directory" sites
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* - [F,L]
# Filter for most common exploits
RewriteCond %{HTTP_USER_AGENT} libwww-perl [OR]
RewriteCond %{QUERY_STRING} tool25 [OR]
RewriteCond %{QUERY_STRING} cmd.txt [OR]
RewriteCond %{QUERY_STRING} cmd.gif [OR]
RewriteCond %{QUERY_STRING} r57shell [OR]
RewriteCond %{QUERY_STRING} c99 [OR]
The 2nd code block above ("Filter for most common exploits") is incomplete and should not have a trailing OR flag (that would potentially block everyone!). These two code blocks also repeat the same code and should be combined. The RewriteBase directive is also redundant and can be removed. The above should be rewritten as:
# Do not allow Perl script hackers, as they are probably just feeding useless Adsense "directory" sites
# and Filter for most common exploits
RewriteCond %{HTTP_USER_AGENT} libwww-perl [OR]
RewriteCond %{QUERY_STRING} tool25 [OR]
RewriteCond %{QUERY_STRING} cmd.txt [OR]
RewriteCond %{QUERY_STRING} cmd.gif [OR]
RewriteCond %{QUERY_STRING} r57shell [OR]
RewriteCond %{QUERY_STRING} c99
RewriteRule .* - [F]
The F flag implies L, so the L flag is not required here.
UPDATE#2: Again, I cannot see anything in your VirtualHost container that would cause these problems (although, to be honest, I'm struggling to even imagine what could be causing this behaviour).
However, the following line is suspicious:
Options Indexes FollowSymLinks MultiViews
Why do you need MultiViews? Also, do you need Indexes? Most sites will disable these options as they can expose your file structure and result in unexpected behaviour (unless that behaviour is intentional of course). However, FollowSymLinks is required for mod_rewrite.
If these options are not required then try removing them:
Options FollowSymLinks
Incidentally, these options can also be disabled in .htaccess with the following directive (note that here the options are preceded with -):
Options -Indexes -MultiViews

What is missing or wrong with my .htaccess file?

I know nothing about .htaccess files so I would like to ask you guys some help. I will list the things I was trying to do with code and that is not working.
Remove .html and .php from my url (get a clean link I mean);
Compress files like images and .js/.css (Google speedtest says it is not happening);
Make the website works with and without www (standard would be without www);
Well that's it. Thank you in advance for you help!!
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
<FilesMatch "(\. (engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)? |xtmpl)|code-style\.pl|Entries.*|Repository|Root|Tag|Template)$">
Order allow,deny
</FilesMatch>
Options -Indexes
RewriteEngine on
RewriteRule ^/abc/(.*)$ /new/$1 [R=301,L]
RewriteEngine on
RewriteRule ^/def/(.*)\.html$ /new2/$1.html [R=301,L]
RewriteEngine on
RewriteRule ^/ghi/(.*)\.(html|htm)$ /new3/$1.$2 [R=301,L]
RewriteEngine on
RewriteRule ^/jkl/(.*)$ http://www.mywebsite.com/$1 [R=301,L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
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 month"
ExpiresDefault "access 1 month"
</IfModule>
To get automatic redirection in Apache you can consider using MultiViews, which is easy to enable and backwards-compatible. For example, with this one line in your .htaccess file:
Options +MultiViews
You can now access the same file from these URLs:
/def/search.html
/def/search
After that it's a matter of changing the HTML files so they link to the URLs without the file suffix. This is a significant undertaking (but there are some tools that might help).
As for the gzip attempt, others on StackOverflow seem to recommend mod_deflate in preference to mod_gzip as it is easier to configure. See this page for instructions on using mod_deflate (just below the mod_gzip instructions).
Finally, you can use mod_rewrite to redirect to the canonical URL without the www prefix. Example for www.example.com:
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^/(.*) http://example.com/$1 [L,R=301]
Why not use a file like here:
GitHub - Apache Server Configs
This .htaccess already has configurations for compression etc.
I think that you will be able to add to the file everything that need for you for example you can add type of flashplayer's files.

Prestashop: new domain still pointing to old url and unable to access back-end

I am in the process of cloning my shop ahead of a much dreaded prestashop upgrade (best practice here). My shop is up and running in a subfolder of my root (/.) dir (ex: mydomain.com/shop/).
I followed all the instructions given, namely:
Created a new folder in my root (/.) directory -> /newfolder/
Exported prestashop database to my hard drive
Copied all my prestashop files to my hard drive (using FTP)
Created new database and imported the local back-up
Uploaded all my files from hard drive to new folder
Updated my config/settings.inc.php with new database credentials
(Also updated config/settings.inc.old.php and config/settings.old.php just in case)
Updated the physical_uri field of my ps_shop_url table to /newfolder/
Didn't edit the DOMAIN and SSL_DOMAIN fields of ps_configuration because domain remained unchanged (ex: mydomain.com)
Even removed all files from cache/smarty/cache and cache/smarty/compile except the index.php
Removed newfolder/.htaccess
Cleared my browser cookies and cache (multiple times)
At this point I tried to connect to my new domain (ex: mydomain.com/newfolder) and I was redirected to my old url (ex: mydomain.com/shop).
I then tried to access the back-office of my new shop (ex: mydomain.com/newfolder/admin1) and when I input my credential I get redirected to the exact same log-in page with no error message whatsoever.
What am I missing guys ?
Any help appreciated,
Thanks !
C
btw:
version of Prestashop (for both folders) is 1.6.0.14
site is hosted on 1and1 servers
db are mysql 5.1 for current shop, 5.5 for clone shop
EDIT #1 :
Here is my newfolder/.htaccess :
`Options +FollowSymLinks
# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>
# Disable Multiviews
Options -Multiviews
RewriteEngine on
#Domain: lademo.fr
RewriteRule . - [E=REWRITEBASE:/shop/]
RewriteRule ^api$ api/ [L]
RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
# Images
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$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])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]
# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/x-font-woff .woff
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|svg)$">
Header add Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
<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"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
ExpiresByType application/font-woff "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType font/opentype "access plus 1 year"
ExpiresByType font/ttf "access plus 1 year"
ExpiresByType font/otf "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/x-font-otf "access plus 1 year"
</IfModule>
<IfModule mod_headers.c>
Header unset Etag
</IfModule>
FileETag none
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/x-javascript font/ttf application/x-font-ttf font/otf application/x-font-otf font/opentype
</IfModule>
</IfModule>
#If rewrite mod isn't enabled
ErrorDocument 404 /shop/index.php?controller=404
# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again