Make PHP-FPM security.limit_extensions case insensitive - security

Make PHP-FPM security.limit_extensions case insensitive;
I have set the option to the following:
security.limit_extensions = .php .php3 .php4 .php5 .php7 .html .phtml .phps .js
Why am I using .js in it? Because I have dynamic JS content which changes a little bit of stuff sometimes...
But it throws out a 403 Forbidden message when I change the file extension to .HTML, or .JS for example.
It only works for lower case.

The dumbest way is to simply write out all possible case variants in the setting. The following bash command
echo security.limit_extensions = .{P,p}{H,h}{P,p}{,3,4,5,7,S,s} .{P,p,}{H,h}{T,t}{M,m}{L,l} .{J,j}{S,s}
will generate them all, namely:
security.limit_extensions = .PHP .PHP3 .PHP4 .PHP5 .PHP7 .PHPS .PHPs .PHp .PHp3 .PHp4 .PHp5 .PHp7 .PHpS .PHps .PhP .PhP3 .PhP4 .PhP5 .PhP7 .PhPS .PhPs .Php .Php3 .Php4 .Php5 .Php7 .PhpS .Phps .pHP .pHP3 .pHP4 .pHP5 .pHP7 .pHPS .pHPs .pHp .pHp3 .pHp4 .pHp5 .pHp7 .pHpS .pHps .phP .phP3 .phP4 .phP5 .phP7 .phPS .phPs .php .php3 .php4 .php5 .php7 .phpS .phps .PHTML .PHTMl .PHTmL .PHTml .PHtML .PHtMl .PHtmL .PHtml .PhTML .PhTMl .PhTmL .PhTml .PhtML .PhtMl .PhtmL .Phtml .pHTML .pHTMl .pHTmL .pHTml .pHtML .pHtMl .pHtmL .pHtml .phTML .phTMl .phTmL .phTml .phtML .phtMl .phtmL .phtml .HTML .HTMl .HTmL .HTml .HtML .HtMl .HtmL .Html .hTML .hTMl .hTmL .hTml .htML .htMl .htmL .html .JS .Js .jS .js
I would, however, instead suggest just changing your extensions to be lowercase. You can use an utility such as rename to do just that:
shopt -s globstar
rename 's!(\.\w+)+$!lc $&!e' **/*.*

Related

How to config htaccess to html can execute php

I want to configure the htaccess file to execute php file in html, but I get an error 500 Internal Server.
this here:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
AddType application/x-httpd-php .html .htm
</IfModule>

How to Redirect 301 with .php in the link

i have following problem, i cant Redirect 301 via .htaccess example:
Redirect 301 /wellnesshotel.php/fotogalerie/ /wellnesshotel/bilder-und-videos/
the page where the redirection comes is http://www.domain.de//fotogalerie/ but why?
Thanks a lot
`
# BEGIN HTTPS Redirection Plugin
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# END HTTPS Redirection Plugin
# BEGIN WpFastestCache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^www.my-domain.de
# Start WPFC Exclude
RewriteCond %{REQUEST_URI} !wellnessurlaub/wellness-angebote [NC]
# End WPFC Exclude
# Start_WPFC_Exclude_Admin_Cookie
RewriteCond %{HTTP:Cookie} !wordpress_logged_in_[^\=]+\=Anke|Buckermann|MarcelM|Mudrich|Steffen
RewriteCond %{HTTP:Cookie} !wordpress_logged_in_[^\=]+\=Taptap|Tina|Tobias|Valentin|Walera
RewriteCond %{HTTP:Cookie} !wordpress_logged_in_[^\=]+\=Xenia
# End_WPFC_Exclude_Admin_Cookie
RewriteCond %{HTTP_HOST} ^www.my-domain.de
RewriteCond %{HTTP_USER_AGENT} !(facebookexternalhit|WhatsApp|Mediatoolkitbot)
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_URI} !(\/){2}$
RewriteCond %{REQUEST_URI} \/$
RewriteCond %{QUERY_STRING} !.+
RewriteCond %{HTTP:Cookie} !comment_author_
RewriteCond %{HTTP:Cookie} !wp_woocommerce_session
RewriteCond %{HTTP:Cookie} !safirmobilswitcher=mobil
RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP_USER_AGENT} !^.*(\bCrMo\b|CriOS|Android.*Chrome\/[.0-9]*\s(Mobile)?|\bDolfin\b|Opera.*Mini|Opera.*Mobi|Android.*Opera|Mobile.*OPR\/[0-9.]+|Coast\/[0-9.]+|Skyfire|Mobile\sSafari\/[.0-9]*\sEdge|IEMobile|MSIEMobile|fennec|firefox.*maemo|(Mobile|Tablet).*Firefox|Firefox.*Mobile|FxiOS|bolt|teashark|Blazer|Version.*Mobile.*Safari|Safari.*Mobile|MobileSafari|Tizen|UC.*Browser|UCWEB|baiduboxapp|baidubrowser|DiigoBrowser|Puffin|\bMercury\b|Obigo|NF-Browser|NokiaBrowser|OviBrowser|OneBrowser|TwonkyBeamBrowser|SEMC.*Browser|FlyFlow|Minimo|NetFront|Novarra-Vision|MQQBrowser|MicroMessenger|Android.*PaleMoon|Mobile.*PaleMoon|Android|blackberry|\bBB10\b|rim\stablet\sos|PalmOS|avantgo|blazer|elaine|hiptop|palm|plucker|xiino|Symbian|SymbOS|Series60|Series40|SYB-[0-9]+|\bS60\b|Windows\sCE.*(PPC|Smartphone|Mobile|[0-9]{3}x[0-9]{3})|Window\sMobile|Windows\sPhone\s[0-9.]+|WCE;|Windows\sPhone\s10.0|Windows\sPhone\s8.1|Windows\sPhone\s8.0|Windows\sPhone\sOS|XBLWP7|ZuneWP7|Windows\sNT\s6\.[23]\;\sARM\;|\biPhone.*Mobile|\biPod|\biPad|Apple-iPhone7C2|MeeGo|Maemo|J2ME\/|\bMIDP\b|\bCLDC\b|webOS|hpwOS|\bBada\b|BREW).*$ [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/all/$1/index.html -f [or]
RewriteCond /usr/www/users/zumckp/ice-media/wp-content/cache/all/$1/index.html -f
RewriteRule ^(.*) "/wp-content/cache/all/$1/index.html" [L]
##### mobile #####
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^www.my-domain.de
# Start WPFC Exclude
RewriteCond %{REQUEST_URI} !wellnessurlaub/wellness-angebote [NC]
# End WPFC Exclude
# Start_WPFC_Exclude_Admin_Cookie
RewriteCond %{HTTP:Cookie} !wordpress_logged_in_[^\=]+\=Anke|Buckermann|MarcelM|Mudrich|Steffen
RewriteCond %{HTTP:Cookie} !wordpress_logged_in_[^\=]+\=Taptap|Tina|Tobias|Valentin|Walera
RewriteCond %{HTTP:Cookie} !wordpress_logged_in_[^\=]+\=Xenia
# End_WPFC_Exclude_Admin_Cookie
RewriteCond %{HTTP_HOST} ^www.my-domain.de
RewriteCond %{HTTP_USER_AGENT} !(facebookexternalhit|WhatsApp|Mediatoolkitbot)
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_URI} !(\/){2}$
RewriteCond %{REQUEST_URI} \/$
RewriteCond %{QUERY_STRING} !.+
RewriteCond %{HTTP:Cookie} !comment_author_
RewriteCond %{HTTP:Cookie} !wp_woocommerce_session
RewriteCond %{HTTP:Cookie} !safirmobilswitcher=masaustu
RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP_USER_AGENT} ^.*(\bCrMo\b|CriOS|Android.*Chrome\/[.0-9]*\s(Mobile)?|\bDolfin\b|Opera.*Mini|Opera.*Mobi|Android.*Opera|Mobile.*OPR\/[0-9.]+|Coast\/[0-9.]+|Skyfire|Mobile\sSafari\/[.0-9]*\sEdge|IEMobile|MSIEMobile|fennec|firefox.*maemo|(Mobile|Tablet).*Firefox|Firefox.*Mobile|FxiOS|bolt|teashark|Blazer|Version.*Mobile.*Safari|Safari.*Mobile|MobileSafari|Tizen|UC.*Browser|UCWEB|baiduboxapp|baidubrowser|DiigoBrowser|Puffin|\bMercury\b|Obigo|NF-Browser|NokiaBrowser|OviBrowser|OneBrowser|TwonkyBeamBrowser|SEMC.*Browser|FlyFlow|Minimo|NetFront|Novarra-Vision|MQQBrowser|MicroMessenger|Android.*PaleMoon|Mobile.*PaleMoon|Android|blackberry|\bBB10\b|rim\stablet\sos|PalmOS|avantgo|blazer|elaine|hiptop|palm|plucker|xiino|Symbian|SymbOS|Series60|Series40|SYB-[0-9]+|\bS60\b|Windows\sCE.*(PPC|Smartphone|Mobile|[0-9]{3}x[0-9]{3})|Window\sMobile|Windows\sPhone\s[0-9.]+|WCE;|Windows\sPhone\s10.0|Windows\sPhone\s8.1|Windows\sPhone\s8.0|Windows\sPhone\sOS|XBLWP7|ZuneWP7|Windows\sNT\s6\.[23]\;\sARM\;|\biPhone.*Mobile|\biPod|\biPad|Apple-iPhone7C2|MeeGo|Maemo|J2ME\/|\bMIDP\b|\bCLDC\b|webOS|hpwOS|\bBada\b|BREW).*$ [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/wpfc-mobile-cache/$1/index.html -f [or]
RewriteCond /usr/www/users/zumckp/ice-media/wp-content/cache/wpfc-mobile-cache/$1/index.html -f
RewriteRule ^(.*) "/wp-content/cache/wpfc-mobile-cache/$1/index.html" [L]
##### mobile #####
</IfModule>
<FilesMatch "index\.(html|htm)$">
AddDefaultCharset UTF-8
<ifModule mod_headers.c>
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Mon, 29 Oct 1923 20:30:00 GMT"
</ifModule>
</FilesMatch>
# END WpFastestCache
# BEGIN GzipWpFastestCache
<IfModule mod_deflate.c>
AddType x-font/woff .woff
AddType x-font/ttf .ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/opentype font/ttf font/eot font/otf
</IfModule>
# END GzipWpFastestCache
# BEGIN LBCWpFastestCache
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|webp|js|css|swf|x-html|css|xml|js|woff|woff2|ttf|svg|eot)(\.gz)?$">
<IfModule mod_expires.c>
AddType application/font-woff2 .woff2
ExpiresActive On
ExpiresDefault A0
ExpiresByType image/webp A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/ico A2592000
ExpiresByType image/svg+xml A2592000
ExpiresByType text/css A2592000
ExpiresByType text/javascript A2592000
ExpiresByType application/javascript A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType application/font-woff2 A2592000
</IfModule>
<IfModule mod_headers.c>
Header set Expires "max-age=2592000, public"
Header unset ETag
Header set Connection keep-alive
FileETag None
</IfModule>
</FilesMatch>
# END LBCWpFastestCache
# BEGIN WEBPWpFastestCache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{REQUEST_URI} \.(jpe?g|png)
RewriteCond %{DOCUMENT_ROOT}/$1.webp -f [or]
RewriteCond /usr/www/users/zumckp/ice-media/$1.webp -f
RewriteRule ^(.*) "/$1.webp" [L]
</IfModule>
<IfModule mod_headers.c>
Header append Vary Accept env=REDIRECT_accept
</IfModule>
AddType image/webp .webp
# END WEBPWpFastestCache
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# WORKING REDIRECTS
RewriteEngine On
Redirect 301 /hotel/wellnessurlaub.php/bernkastel-kues /kontakt-infomationen/service/hotel-faqs-von-a-z/
Redirect 301 /wellness/wellnessreisen.php/verwoehnhotel /wellnesshotel/bilder-und-videos/
Redirect 301 /hotel-buchen/wellnesshotel.php/hotel/angebote-pauschalen.html /wellnessurlaub/
Redirect 301 /hotel-buchen/wellnesshotel.php/hotel/zimmer /wellnessurlaub/zimmer/
Redirect 301 /hotel-buchen/wellnesshotel.php/hotel/anwendungen/ /wellnessurlaub/anwendungen/
Redirect 301 /dayspa/ /wellnessurlaub/day-spa/
Redirect 301 /bewei/ /wellness/bewei/
Redirect 301 /tcm/traditionelle-chinesische-medizin.php/alternative-medizin /tcm/
Redirect 301 /beauty/medical-beauty.php/schoenheitsfarm /wellness/spa/
Redirect 301 /restaurant/vitalhotel.php/fuenf-elemente-kueche /wellnesshotel/kulinarik/
Redirect 301 /freizeit/fitness-hotel.php/ferien/ /wellnesshotel/mosel-und-freizeit/wander-und-spazierwege-ab-hotel/
Redirect 301 /aktuelles/urlaub-deutschland.php/mosel/ /wellnesshotel/ueber-uns/news/
Redirect 301 /videos/ /wellnesshotel/bilder-und-videos/
Redirect 301 /wellness-abc/ https://www.my-domain.de/wellness/wellness-abc/
Redirect 301 /urlaub/rueckruf-service/ /kontakt-infomationen/kontakt/
Redirect 301 /wellnesshotel.php/urlaub/rueckruf-service/ /kontakt-infomationen/kontakt/
Redirect 301 /wellnesshotel.php/urlaub/anreise /wellnesshotel/anreise-und-entfernungen/
Redirect 301 /wellness-abc/ /wellness/wellness-abc/
Redirect 301 /angebote /wellnessurlaub/wellness-angebote/
Redirect 301 /wellnesshotel.php/urlaub/gaestebuch/gaestebuch /
Redirect 301 /wellnesshotel.php/angebote /wellnessurlaub/wellness-angebote/
Redirect 301 /wellnesshotel.php/urlaub/kontakt /kontakt-infomationen/kontakt/
Redirect 301 /wellnesshotel.php/urlaub/gutschein/ /wellnessurlaub/wellness-gutschein/
Redirect 301 /wellnesshotel.php/urlaub/wellnesshotel-prospekte/ /kontakt-infomationen/service/wellnesshotel-prospekte/
Redirect 301 /wellnesshotel.php/urlaub/uebersicht /sitemap/
Redirect 301 /wellnesshotel.php/urlaub/impressum /impressum/
Redirect 301 /wellnesshotel.php/urlaub/presse-center /kontakt-infomationen/kontakt/
Redirect 301 /wellnesshotel.php/urlaub/shops /tcm/shop/
Redirect 301 /wellnesshotel.php/urlaub/newsletter /kontakt-infomationen/service/newsletter/
Redirect 301 /angebote-und-preise/wellness.php/wellness-angebote/ /wellnessurlaub/wellness-angebote/
Redirect 301 /angebote-und-preise/wellness.php/wellness-angebote /wellnessurlaub/wellness-angebote/
# NOT WORKING REDIRECTS
RewriteEngine On
Redirect 301 /hotel/wellnessurlaub.php/bernkastel-kues/blackvip-im-wellnesshotel-zum-kurfuersten /kontakt-infomationen/service/black-vip/
Redirect 301 /aktuelles/urlaub-deutschland.php/mosel/stellenangebote/ /wellnesshotel/ueber-uns/jobs/
Redirect 301 /hotel/wellnessurlaub.php/bernkastel-kues/nachhaltigkeit /wellnesshotel/ueber-uns/nachhaltigkeit
Redirect 301 /hotel/wellnessurlaub.php/bernkastel-kues/ausstattungsmerkmale /kontakt-infomationen/service/hotel-faqs-von-a-z/
Redirect 301 /hotel/wellnessurlaub.php/bernkastel-kues/serviceleistungen /kontakt-infomationen/service/hotel-faqs-von-a-z/
Redirect 301 /hotel/wellnessurlaub.php/bernkastel-kues/gesellschaftliches-und-soziales-engagement /wellnesshotel/ueber-uns/nachhaltigkeit/
Redirect 301 /hotel/wellnessurlaub.php/bernkastel-kues/entfernungen /kontakt-infomationen/service/hotel-faqs-von-a-z/
Redirect 301 /angebote-und-preise/wellness.php/wellness-angebote/hotel/an-und-abreise /kontakt-infomationen/service/hotel-faqs-von-a-z/
Redirect 301 /angebote-und-preise/wellness.php/wellness-angebote/hotel/bezahlung-storno /kontakt-infomationen/service/hotel-faqs-von-a-z/
Redirect 301 /angebote-und-preise/wellness.php/wellness-angebote/hotel/saisonzeiten /kontakt-infomationen/service/hotel-faqs-von-a-z/
Redirect 301 /angebote-und-preise/wellness.php/wellness-angebote/hotel/fruehstueckszeiten /kontakt-infomationen/service/hotel-faqs-von-a-z/
Redirect 301 /angebote-und-preise/wellness.php/wellness-angebote/hotel/fuer-kinder /kontakt-infomationen/service/hotel-faqs-von-a-z/
Redirect 301 /angebote-und-preise/wellness.php/wellness-angebote/hotel/hunde-mitbringen /kontakt-infomationen/service/hotel-faqs-von-a-z/
Redirect 301 /angebote-und-preise/wellness.php/wellness-angebote/hotel/unsere-kueche /wellnesshotel/kulinarik/
Redirect 301 /angebote-und-preise/wellness.php/wellness-angebote/hotel/wissenswertes /kontakt-infomationen/service/hotel-faqs-von-a-z/
Redirect 301 /restaurant/vitalhotel.php/fuenf-elemente-kueche/gutes-essen-haelt-leib-und-seele-zusammen /wellnesshotel/kulinarik
Redirect 301 /restaurant/vitalhotel.php/fuenf-elemente-kueche/waffelrezept-ein-bisschen-gesund /wellnesshotel/kulinarik/
Redirect 301 /restaurant/vitalhotel.php/fuenf-elemente-kueche/speisekarte-mittag /wellnesshotel/kulinarik/
Redirect 301 /restaurant/vitalhotel.php/fuenf-elemente-kueche/speisekarte-abend /wellnesshotel/kulinarik/
Redirect 301 /restaurant/vitalhotel.php/fuenf-elemente-kueche/vital-schlemmen /wellnesshotel/kulinarik/
Redirect 301 /restaurant/vitalhotel.php/fuenf-elemente-kueche/einzigartige-kueche /wellnesshotel/kulinarik/
Redirect 301 /wellness/wellnessreisen.php/verwoehnhotel/tcm-wellness-abc /tcm/alternative-medizin/tcm-glossar/
Redirect 301 /wellness/wellnessreisen.php/verwoehnhotel/praeventionsangebote /kontakt-infomationen/service/hotel-faqs-von-a-z/
Redirect 301 /wellness/wellnessreisen.php/verwoehnhotel/wellnessurlaub-mosel /wellnesshotel/mosel-und-freizeit/
Redirect 301 /wellness/wellnessreisen.php/verwoehnhotel/fitness-cardio-fitness /wellness/kurse-aktivitaeten/fitness/
Redirect 301 /wellness/wellnessreisen.php/verwoehnhotel/praeventions-kurse /kontakt-infomationen/service/hotel-faqs-von-a-z/
Redirect 301 /wellness/wellnessreisen.php/verwoehnhotel/panorama-schwimmbad /
Redirect 301 /wellness/wellnessreisen.php/verwoehnhotel/wellness-im-hotel-zum-kurfuersten /
Redirect 301 /wellness/wellnessreisen.php/verwoehnhotel/zuschuesse /kontakt-infomationen/service/hotel-faqs-von-a-z/
Redirect 301 /wellness/wellnessreisen.php/verwoehnhotel/wellness-hotels-resorts /kontakt-infomationen/service/hotel-faqs-von-a-z/
# enable php compression
php_value zlib.output_compression 1
php_value zlib.output_compression_level 6
# enable apache compression
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE application/* text/* font/* image/x-icon image/svg+xml
</IfModule>
</IfModule>`

Redirect api/ request to api.php and all other request to index.php

Am building an api for an existing application which redirects all request to index.php. But now i want to direct all request with api to api.php e.g Redirect http://domain.com/api/user/create to api.php and other requests without api e.g www.domain.com/users/all to index.php
Here is my htaccess
Options -Indexes
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/font-woff .woff
AddType image/svg+xml svg
AddType image/svg+xml svgz
<IfModule mod_rewrite.c>
#Fix Rewrite
Options -Multiviews
RewriteEngine On
#Live version goes here
#RewriteBase /
#Dev config goes here
RewriteBase /myapp
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*,:*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^var.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
## always send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(media|theme|js|screens)/
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

Htaccess rewrite to rename the first folder, remove the second, and substitute the file name's underscores with hyphens

There are a number of external sites pointing back to our site looking for the following url:
domain.com/bananas/ripe/name_of_file
I'd like to add a rule to the htaccess file that would redirect requests of this type (looking for the same name_of_file) to:
domain.com/apples/name-of-file #notice the hyphens
I've tried a few variations of
RewriteCond %{THE_REQUEST} \ /bananas/ripe/
RewriteRule ^bananas/ripe/(.*)$ /apples/$1 [L,R=301]
But it's not happening because I don't know how to go about replacing the underscores of the name_of_file to hyphens of name-of-file.
Full htaccess:
<Files .htaccess>
order allow,deny
deny from all
</Files>
# Don't show any directory without an index file
Options -Indexes
# Dont list files in index pages
IndexIgnore *
# Don't need to tell everyone we're apache
ServerSignature Off
<FilesMatch "\.(ttf|otf|eot|woff|font.css)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
AddType application/x-shockwave-flash .swf
AddType video/mpeg .mpeg .mpg .mpe
AddType video/quicktime .qt .mov .m4v .flac
AddType video/x-msvideo .avi
AddType video/x-sgi-movie .movie
AddType video/ogg .ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm
AddType audio/x-aiff .aif .aiff .aifc
AddType audio/x-wav .wav
AddType audio/x-pn-realaudio .ram
AddType image/svg+xml .svg .svgz
AddEncoding gzip .svgz
AddType application/vnd.ms-fontobject .eot
AddType font/truetype .ttf
AddType font/opentype .otf
AddType font/woff .woff
AddType image/gif .gif .GIF
AddType image/jpeg .jpeg .jpg .jpe .JPG
AddType image/vnd.microsoft.icon .ico
AddType text/x-component .htc
AddType text/xml .xml
AddType text/x-component .htc
AddDefaultCharset utf-8
AddCharset utf-8 .html .css .js .xml .json .rss
ErrorDocument 403 http://domain.com
ErrorDocument 404 /index.php?/home/error
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{QUERY_STRING} ^(ACT=.*)$ [NC,OR]
RewriteCond %{QUERY_STRING} ^(URL=.*)$ [NC,OR]
RewriteCond %{QUERY_STRING} ^(CSS=.*)$ [NC]
RewriteRule ^(.*)$ /index.php\?&%{QUERY_STRING} [L]
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^bananas/ripe/(.*)$ /apples/$1 [L,NC,R]
# if there is only one underscore then repalce it by - and redirect
RewriteRule ^(apples)/([^_]*)_([^_]*)$ /$1/$2-$3 [L,R=302]
# if there are more than one underscores then "repeatedly" repalce it by -
# and set env var
RewriteRule ^(apples)/([^_]*)_([^_]*)_(.*) $1/$2-$3-$4 [E=USCOR:1]
# if USCORE env var is set and there is no underscore left then redirect
RewriteCond %{ENV:REDIRECT_USCOR} =1
RewriteRule ^(apples)/([^_]+)$ /$1/$2 [L,R=302]
<FilesMatch "\.(html|htm|php)$">
Header set imagetoolbar "no"
</FilesMatch>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png|mov|svg|mp4)$ [NC]
RewriteCond %{HTTP_REFERER} !^https?://([^.]+\.)?domain\. [NC]
RewriteCond %{HTTP_REFERER} domain:8888\. [NC]
RewriteRule \.(gif|jpe?g?|png)$ - [F,NC,L]
</ifModule>
You can use these rules:
RewriteRule ^bananas/ripe/(.*)$ /apples/$1 [L,NC,R=302]
# if there is one underscore left then redirect
RewriteRule ^(apples)/([^_]*)_([^_]*)/?$ /$1/$2-$3 [NC,L,R=302]
# if there are more than one underscores then "repeatedly" repalce it by -
RewriteRule ^(apples)/([^_]*)_(.*)$ $1/$2-$3 [NC,L]

Disable URL Rewrite for subdomain

I'm using Apache web server ( use .htaccess to handle URL Rewrite ).
the main domain ( e.g. example.com ) is managed by URL Rewrite generated by WordPress. The URL Rewrite applies for whole domain , including sub-domains.
I have a new subdomain called http://static.example.com, which acts a URL forward to another external URL, e.g. forward to http://www.google.com. That's :
http://static.example.com/style.css will forward to http://www.google.com/css/some_path/style.css
However, the URL Rewrite blocks it, and reports file not found, as it cannot find the /css/style.css in local server. My question is: How to disable URL Rewrite for subdomain ?
The current .htaccess is as follow:
RewriteEngine on
AddType application/rss+xml rss
AddType application/x-java-jnlp-file jnlp
Options All -Indexes
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^/?$ "http\:\/\/example\.com" [R=301,L]
# BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
<IfModule mod_mime.c>
# DEFLATE by extension
AddOutputFilter DEFLATE js css htm html xml
</IfModule>
</IfModule>
<FilesMatch "\.(css|htc|js|js2|js3|js4|CSS|HTC|JS|JS2|JS3|JS4)$">
<IfModule mod_headers.c>
Header set X-Powered-By "W3 Total Cache/0.9.2.11"
</IfModule>
</FilesMatch>
<FilesMatch "\.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|HTML|HTM|RTF|RTX|SVG|SVGZ|TXT|XSD|XSL|XML)$">
<IfModule mod_headers.c>
Header set X-Powered-By "W3 Total Cache/0.9.2.11"
</IfModule>
</FilesMatch>
<FilesMatch "\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip|ASF|ASX|WAX|WMV|WMX|AVI|BMP|CLASS|DIVX|DOC|DOCX|EOT|EXE|GIF|GZ|GZIP|ICO|JPG|JPEG|JPE|JSON|MDB|MID|MIDI|MOV|QT|MP3|M4A|MP4|M4V|MPEG|MPG|MPE|MPP|OTF|ODB|ODC|ODF|ODG|ODP|ODS|ODT|OGG|PDF|PNG|POT|PPS|PPT|PPTX|RA|RAM|SVG|SVGZ|SWF|TAR|TIF|TIFF|TTF|TTC|WAV|WMA|WRI|XLA|XLS|XLSX|XLT|XLW|ZIP)$">
<IfModule mod_headers.c>
Header set X-Powered-By "W3 Total Cache/0.9.2.11"
</IfModule>
</FilesMatch>
# END W3TC Browser Cache
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^static\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.static\.example\.com$
RewriteRule ^/?$ "https\:\/\/google\.com\/css\/some_path\/" [R=301,L]
Note: note that the forwarding is actually included above.
p.s. all URLs are fake.
replace
RewriteCond %{HTTP_HOST} ^static\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.static\.example\.com$
RewriteRule ^/?$ "https\:\/\/google\.com\/css\/some_path\/" [R=301,L]
with
RewriteCond %{HTTP_HOST} ^(www\.)?static\.example\.com$
RewriteRule ^(.*)$ https://google.com/css/some_path/$1 [R=301,L]
the whole htaccess would be: (adjusted)
RewriteEngine on
AddType application/rss+xml rss
AddType application/x-java-jnlp-file jnlp
Options All -Indexes
# BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
<IfModule mod_mime.c>
# DEFLATE by extension
AddOutputFilter DEFLATE js css htm html xml
</IfModule>
</IfModule>
<FilesMatch "\.(css|htc|js|js2|js3|js4|CSS|HTC|JS|JS2|JS3|JS4)$">
<IfModule mod_headers.c>
Header set X-Powered-By "W3 Total Cache/0.9.2.11"
</IfModule>
</FilesMatch>
<FilesMatch "\.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|HTML|HTM|RTF|RTX|SVG|SVGZ|TXT|XSD|XSL|XML)$">
<IfModule mod_headers.c>
Header set X-Powered-By "W3 Total Cache/0.9.2.11"
</IfModule>
</FilesMatch>
<FilesMatch "\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip|ASF|ASX|WAX|WMV|WMX|AVI|BMP|CLASS|DIVX|DOC|DOCX|EOT|EXE|GIF|GZ|GZIP|ICO|JPG|JPEG|JPE|JSON|MDB|MID|MIDI|MOV|QT|MP3|M4A|MP4|M4V|MPEG|MPG|MPE|MPP|OTF|ODB|ODC|ODF|ODG|ODP|ODS|ODT|OGG|PDF|PNG|POT|PPS|PPT|PPTX|RA|RAM|SVG|SVGZ|SWF|TAR|TIF|TIFF|TTF|TTC|WAV|WMA|WRI|XLA|XLS|XLSX|XLT|XLW|ZIP)$">
<IfModule mod_headers.c>
Header set X-Powered-By "W3 Total Cache/0.9.2.11"
</IfModule>
</FilesMatch>
# END W3TC Browser Cache
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# redirect www.example.com/some to example.com/some
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?static\.example\.com$
RewriteRule ^(.*)$ https://google.com/css/some_path/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Resources