htaccess adding ending slash to some images and not others - .htaccess

New to htaccess... All files exist despite 404. There are actual 50+ images in this one folder but 3 images are getting a slash added to the end.
not working:
http://shawnrieger.dev/img/photography/small/20100402153906_s.jpg/
http://shawnrieger.dev/img/photography/small/20140404123054_s.jpg/
http://shawnrieger.dev/img/photography/small/20130330110114_s.jpg/
an example of working:
http://shawnrieger.dev/img/photography/small/20160913190428_s.jpg
http://shawnrieger.dev/img/photography/small/20120613091849_s.jpg
http://shawnrieger.dev/img/photography/small/20120713102800_s.jpg
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^privacy-policy/$ /parts/pages/privacy-policy.php
RewriteRule ^project/([^/]+)/$ /parts/pages/project.php?id=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
<IfModule mod_headers.c>
# WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
# WEEK
<FilesMatch "\.(js|css|swf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
</IfModule>

You must avoid adding trailing slash for real files and also reorder your rules.
Have it like this:
<IfModule mod_headers.c>
# WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
# WEEK
<FilesMatch "\.(js|css|swf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]
RewriteRule ^privacy-policy/$ /parts/pages/privacy-policy.php [L,NC]
RewriteRule ^project/([^/]+)/$ /parts/pages/project.php?id=$1 [L,NC,QSA]
Make suer to clear your browser cache before you test this change.

Related

Mask URLs with .htaccess without breaking the structure

is it possible to mask the url without breaking the structure?
I use LARAVEL
For example:
URL original:
https://site.test/public/store-owner/dashboard
URL masked
https://site.test/public/vendedor/panel
However, all the previous requests are not lost with the original url and the url in the address bar stays with the masked url
My .htaccess file in proyect
I have this code but the url changes in the address bar to the original one.
What I need is that the url mask does not change
RewriteEngine on
RewriteRule ^public/vendedor/panel/?$ public/store-owner/dashboard? [NC]
------------------------
FileETag none
<IfModule mod_rewrite.c>
RewriteEngine On
#Redirect to non-www with https
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
# BEGIN Caching
<ifModule mod_headers.c>
<filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|ttf|otf|woff|woff2|eot|svg)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<filesMatch "\\.(css)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
#<filesMatch "\\.(js)$">
#Header set Cache-Control "max-age=2592000, private"
#</filesMatch>
<filesMatch "\\.(xml|txt)$">
Header set Cache-Control "max-age=2592000, public, must-revalidate"
</filesMatch>
<filesMatch "\\.(html|html|php)$">
Header set Cache-Control "no-store"
</filesMatch>
</ifModule>
# END Caching
<FilesMatch ".(eot|otf|ttf|woff|woff2)">
Header always set Access-Control-Allow-Origin "*"
</FilesMatch>
<Files .json>
Header unset Cache-Control
</Files>
<Files .env>
order allow,deny
Deny from all
</Files>
RewriteEngine On
RewriteBase /
#force https and non-www
RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
# profile redirection
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(.*)\.site.test [NC]
RewriteRule (.*) https://site.test/stores/%1/$1 [L]
Not Sure this works. But just give a try
RewriteEngine on
RewriteRule ^vendedor/panel/?$ public/store-owner/dashboard? [NC]

mod_rewrite rule is not working but I have the correct syntax

So my mod_rewrite rule isn't working to specify a specific php file for a URL.
Options -Indexes
php_value short_open_tag 1
#Caching
# 1 HOUR
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
# 1 HOUR
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
# 1 HOUR
<FilesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=31536000, proxy-revalidate"
</FilesMatch>
<IfModule mod_rewrite.c>
#Rewrite rules
RewriteEngine on
RewriteRule ^about\/special-offers\/?$ about/special-offers.php
# remove www. from all domains
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
# Add trailing slash
# TODO: This breaks POST data when forwarding to a URL without an ending slash
#RewriteCond %{REQUEST_URI} !\.(php|html?|gif|jpe?g|JPE?G|png|bmp|js|swf|css|ico|xml|txt|woff2|woff)$
#RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [P,R=301]
# hide .svn folders
RewriteRule ^(.*/)*\.svn/ / [NC,L]
# send all images and misc files to the actual location
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule \.(gif|jpe?g|JPE?G|png|bmp|js|swf|ico|xml|txt) index.php [NC,L]
# send folder to the relevant php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ $1/$2.php
RewriteRule ^([^/]+)\/([^/]+)\/ $1/$2.php
#RewriteRule ^([^/]+)/([^/]+)/$ $1/$2.php
RewriteRule ^([^/]+)/([^/]+)/$ $1/default.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
# otherwise if the file or directory is not found, process through the index
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
</IfModule>
I have a multitude of other rules in here, I can post them if need be, but since this is a specific rule I don't know why one of them would be overriding it. Direction is appreciated.
I've tried putting it at the top or bottom of my mod_rewrite section but neither seems to have any affect.
Something I've just noticed is that when I go to /about/special-offers/x (where x is any string), it loads the correct page.
Other
Finally fixed this issue, I did it by marking the RewriteRule as final with [L].
Relevant portion:
# send folder to the relevant php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)\/([^/]+)\/ $1/$2.php [L]

how can I allow robot.txt in my .htaccess file

I am trying to make robots.txt and favicon.ico accessible through http. They are both in my app's root directory. I want them to be able to go to mydomain.com/robots.txt and my robots.txt file and same with favicon.ico. I have looked at other examples on the internet and stack overflow but I can't seem to get it working for my specific .htaccess file.
RewriteEngine on
RewriteCond %{REQUEST_URI} !=/server-status
RewriteRule ^folder1/(.+)?$ folder1/$1 [L]
RewriteRule ^folder2/(.+)?$ folder2/$1 [L]
RewriteRule ^folder3/(.+)?$ folder3/$1 [L]
RewriteRule ^folder4/(.+)?$ folder4/$1 [L]
RewriteRule ^robots.txt [L]
RewriteRule ^favicon.ico [L]
RewriteBase /
RewriteRule !\.(gif|jpg|jpeg|png|css|js|php|htaccess|xml|htm|html|swf|pdf)$ index.php
<ifModule mod_headers.c>
# Expires after 1 month
<filesMatch ".(css|js)$">
Header set Cache-Control "max-age=2592000"
</filesMatch>
# Expires after 1 day
<filesMatch ".(jpg|jpeg|gif|png|x-icon)$">
Header set Cache-Control "max-age=31536000"
</filesMatch>
</ifModule>
This worked:
RewriteEngine on
RewriteCond %{REQUEST_URI} !=/server-status
RewriteRule ^folder1/(.+)?$ folder1/$1 [L]
RewriteRule ^folder2/(.+)?$ folder2/$1 [L]
RewriteRule ^folder3/(.+)?$ folder3/$1 [L]
RewriteRule ^folder4/(.+)?$ folder4/$1 [L]
RewriteRule "^robots.txt$" "robots.txt" [L]
RewriteRule "^favicon.ico$" "favicon.ico" [L]
RewriteBase /
RewriteRule !\.(gif|jpg|jpeg|png|css|js|php|htaccess|xml|htm|html|swf|pdf)$ index.php
<ifModule mod_headers.c>
# Expires after 1 month
<filesMatch ".(css|js)$">
Header set Cache-Control "max-age=2592000"
</filesMatch>
# Expires after 1 day
<filesMatch ".(jpg|jpeg|gif|png|x-icon)$">
Header set Cache-Control "max-age=31536000"
</filesMatch>
</ifModule>

htaccess have redirect loop error with php extension

My htaccess
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
DirectorySlash Off
AddDefaultCharset UTF-8
SetEnv TZ Asia/Bsngkok
DefaultLanguage th
ContentDigest On
SetEnv SERVER_ADMIN aaa#aaa.com
RewriteCond %{HTTP_HOST} ^aaa.com$ [NC]
RewriteRule ^(.*)$ http://www.aaa.com/$1 [R=301,L]
##### Add trailing slash ####################################
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.aaa.com/$1/ [R=301,L]
RewriteRule ^(.*)/$ /$1.php [L]
RewriteRule ^audio/([^/\.]+)/?$ /pages/viewAudio.php?id=$1 [L]
<filesMatch "\.(ttf|woff|woff2|eot)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<filesMatch ".(php|cgi)$">
Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
</filesMatch>
<files .htaccess>
order allow,deny
deny from all
</files>
When I go to http://www.aaa.com/audio/test it's loop and has a lot of php like http://www.aaa.com/audio/test.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php/ but I want http://www.aaa.com/audio/test.
That's my way. I change logic and it work fine
<IfModule mod_rewrite.c>
Options +FollowSymlinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
#CustomURL With parameter
RewriteRule ^audio/([A-Za-z-\s0-9]+)/$ /pages/viewAudio.php?slug=$1 [L]
</IfModule>

.htaccess produce 404 page not found in IE

I'm working on Typo3 version 4.7.4. When I can access the Front End of the site in every browser excepts IE (in all version). After replacing the customized .htaccess file to the default .htaccess of the Typo3 version 4.7.4, it works fine. Then I compared both files I couldn't find something different except some more configurations. However, I'm not sure if those new configurations has killed IE. Here is my new .htaccess configuration:
#####################################
### Compression via TYPO3 ###
#####################################
<FilesMatch "\.js\.gzip$">
AddType "text/javascript" .gzip
</FilesMatch>
<FilesMatch "\.css\.gzip$">
AddType "text/css" .gzip
</FilesMatch>
AddEncoding gzip .gzip
##################################################
### Browser caching of resource files ###
##################################################
<FilesMatch "\.(js|css)$">
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 7 days"
</IfModule>
FileETag MTime Size
</FilesMatch>
########################################
### Settings for mod_rewrite ###
########################################
<IfModule mod_rewrite.c>
RewriteEngine On
### Change this path, if your TYPO3 installation is located in a subdirectory of the website root.
#RewriteBase /
### IMPORTANT: This rule has to be the very first RewriteCond in order to work!
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]
RewriteRule ^fileadmin/(.*/)?_recycler_/ - [F]
RewriteRule ^fileadmin/templates/.*(\.txt|\.ts)$ - [F]
RewriteRule ^typo3conf/ext/[^/]+/Resources/Private/ - [F]
#RewriteRule ^(typo3/|t3lib/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
RewriteRule ^typo3$ typo3/index_re.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
############################################################################
### Redirect all users directly to the https version of the page ###
############################################################################
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]
RewriteRule ^(typo3/|t3lib/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
RewriteRule ^typo3$ typo3/index_re.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
#############################
### Miscellaneous ###
#############################
Options -Indexes
########################################################
### Disable *.ts files viewing from Frontend ###
########################################################
<FilesMatch "\.(ts)$">
order deny,allow
deny from all
</FilesMatch>
Any ideas would be appreciated.
Thanks
Thanks maholtz for help.
#####################################
### Compression via TYPO3 ###
#####################################
<FilesMatch "\.js\.gzip$">
AddType "text/javascript" .gzip
</FilesMatch>
<FilesMatch "\.css\.gzip$">
AddType "text/css" .gzip
</FilesMatch>
AddEncoding gzip .gzip
##################################################
### Browser caching of resource files ###
##################################################
<FilesMatch "\.(js|css)$">
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 7 days"
</IfModule>
FileETag MTime Size
</FilesMatch>
########################################
### Settings for mod_rewrite ###
########################################
<IfModule mod_rewrite.c>
RewriteEngine On
### Change this path, if your TYPO3 installation is located in a subdirectory of the website root.
#RewriteBase /
### IMPORTANT: This rule has to be the very first RewriteCond in order to work!
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]
RewriteRule ^fileadmin/(.*/)?_recycler_/ - [F]
RewriteRule ^fileadmin/templates/.*(\.txt|\.ts)$ - [F]
RewriteRule ^typo3conf/ext/[^/]+/Resources/Private/ - [F]
#RewriteRule ^(typo3/|t3lib/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
RewriteRule ^typo3$ typo3/index_re.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# RewriteRule .* index.php [L]
############################################################################
### Redirect all users directly to the https version of the page ###
############################################################################
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]
RewriteRule ^(typo3/|t3lib/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
RewriteRule ^typo3$ typo3/index_re.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
#############################
### Miscellaneous ###
#############################
Options -Indexes
########################################################
### Disable *.ts files viewing from Frontend ###
########################################################
<FilesMatch "\.(ts)$">
order deny,allow
deny from all
</FilesMatch>
Note that the bug is here # RewriteRule .* index.php [L]

Resources