After htaccess changes the css stop working as stylesheet - apache

I have a weird issue with my css files.
After i changed the htaccess file to this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{THE_REQUEST} /eventDetails\.php\?id=([0-9]+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /%1/%2? [L,R]
RewriteRule ^([^/]+)/([^/]+)/?$ /eventDetails.php?id=$1&name=$2 [L]
</IfModule>
my css files stoped loading to ALL the pages of the website.
My public_html folder contains
index.php
profile.php
css -> style.css
js -> owl.carousel.js
.htaccess
With Google Chrome Developer Tools i have this error for the css files
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://something.gr/css/style.css".
and this error for the javascript files
owl.carousel.js:1 Uncaught SyntaxError: Unexpected token <
Some images from the Network Tab.
WITHOUT .htaccess file
As you can see the Content-Type is text/css .. like it should be
WITH .htaccess file
As you can see here the mime.type returns it as a text/html
What i've tried.
First. after <title> html tag i've enternet
<base href="/">
Second. I've tried to change the .htaccess file to this
<IfModule mod_rewrite.c>
RewriteEngine on
AddType application/javascript js
AddType text/css css
RewriteCond %{THE_REQUEST} /eventDetails\.php\?id=([0-9]+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /%1/%2? [L,R]
RewriteRule ^([^/]+)/([^/]+)/?$ /eventDetails.php?id=$1&name=$2 [L]
</IfModule>
And lastly i've checked on my dedicated server usr/local/apache/conf/
on the mime.types file that the text/css css is NOT commented the same as
application/javascript js
I dont know what else i should do.

Your second rule
RewriteRule ^([^/]+)/([^/]+)/?$ /eventDetails.php?id=$1&name=$2 [L]
rewrites /css/style.css to /eventDetails.php?id=css&name=style.css.
If you want to exclude existing files from this rule, you may prefix it with
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
You may also change the first rule to
RewriteCond %{QUERY_STRING} id=([0-9]+)&name=(.+)
RewriteRule ^eventDetails\.php$ /%1/%2? [L,R]
and to prevent a redirect loop we insert at the beginning
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
You don't need this of course, if you keep the existing condition and rule against THE_REQUEST.
So the complete rules become
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{QUERY_STRING} id=([0-9]+)&name=(.+)
RewriteRule ^eventDetails\.php$ /%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /eventDetails.php?id=$1&name=$2 [L]

Related

DirectorySlash Off Configuration

The site is html, I have 3 .html files that have 3 directories with the same name. BTW its apache2 on ubuntu 18
So......
file1.html
/file1
file2.html
/file2 an so on.
No problem if you don't turn off file extensions in your .htaccess file. But when doing that the directory is served up and you get a error. So here is my .htaccess config trying to use DirectorySlash Off. There is some other stuff going on in this file but I thought I'd leave it all in in case there are related cause/effect things going on here.
# BEGIN
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options +MultiViews
DirectorySlash Off
# Rewrite to file when file and directory both exist with the same name
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^([^.]+)$ $1.html [L]
# Allows files to be loaded without extensions
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
# Removes the file extensions
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
Redirects from products to product directory
RewriteRule ^products/(.*)$ /product/$1 [R=301,NC,L]
</IfModule>
# END
You could be able to give a priority to file when it request comes without / with same name with directory as well as removing file extension , html , like this :
DirectorySlash Off
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.(html)[\s?/] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*) /$1.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\/$
RewriteRule ^(.*) %{REQUEST_URI}/ [L,R=302]
Then add your rest rules:
RewriteRule ^products/(.*)$ /product/$1 [R=301,NC,L]
So , by the code above , HTML extension will be removed then server will check first if there is an HTML file match this request then,if there is a directory match this request .
Clear browser cache then test it , if it is Ok , change 302 to 301 to get permanent redirection
For more info , you can also refer to my previous answer :
Remove .php and .html extensions AND have directories with same name?

mod_rewrite multiple RewriteCond conflict

I have a Problem with mod-rewrite.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent]
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
# IE Cache fix?
ExpiresActive On
ExpiresDefault A1
Header append Cache-Control must-revalidate
Redirecting doesn't work and no Styles or Images are showing.
If those three lines are comment out, it works:
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^ index.php [L]
But I need those to redirect any wrong entery to the root. How does this work together? Or why it doesen't work like this?
Try adding a L flag to your redirect. If you don't have one, the request will get flagged as a redirect and mod_rewrite will continue to run the rest of your rules. So this line needs an L:
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
If you have relative URL issues with your images or styles, try adding this to the header of your pages:
<base href="/" />

.htaccess file's puzzling action (code inside)

I have this CMS set up in a folder called localhost:5999/madison/
The .htaccess file (code below) is in the same folder localhost:5999/madison/
If, in a browser, I go to localhost:5999/madison/ or to localhost:5999/madison/index.php or to localhost:5999/madison/xyz where xyz is anything not containing forward slashes, it redirects me to the following file: localhost:5999/madison/inc/views/view-404.php
My question is: Why?
.htaccess code:
RewriteEngine On
ExpiresActive On
#Expire Header
<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "now plus 7 days"
</FilesMatch>
ExpiresByType text/css "now plus 7 days"
ExpiresByType text/html "now plus 7 days"
ExpiresDefault "now plus 7 days"
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css
RewriteRule ^(assets|inc) - [L]
RewriteRule ^admin[/]?$ admin/index
RewriteRule ^admin/edit/(.*)$ index.php?type=admin&action=edit&page=$1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^admin/(.*)$ index.php?type=admin&action=view&page=$1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^login$ index.php?action=view&type=login&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^forgot-password$ index.php?action=view&type=forgot-password&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^edit/user(/)?$ index.php?action=edit&type=user&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^signup(/)?$ index.php?action=edit&type=user&id=0&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^user/([0-9]+)(/)? index.php?action=view&type=note&user=$1&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^(suggestion|comment)/([0-9]+)(/)? index.php?action=view&type=note&page=open&note_type=$1&note=$2&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^([0-9A-Za-z\-_]+)/(suggestion|comment)/([0-9]+)(/)? index.php?action=view&type=note&page=$1&note_type=$2&note=$3&%1 [L]
#Catch All Pages
RewriteRule ^index\.php$ - [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^([0-9A-Za-z\-_]+)(/)? index.php?action=view&type=page&page=$1&%1 [L]
The issue arises because you are hosting the CMS in a sub-folder localhost:5999/madison/ (without changes to the configuration file) and not directly in localhost:5999/
To solve the issue, make the following changes to config.php in /madison/inc/ directory:
config.php
/**
* Server Definitions
*/
define('SERVER_ABS', $_SERVER['DOCUMENT_ROOT']);
define('SERVER_URL', 'http://'.$_SERVER['HTTP_HOST']);
To:
/**
* Server Definitions
*/
define('SERVER_ABS', $_SERVER['DOCUMENT_ROOT'].'/madison');
define('SERVER_URL', 'http://'.$_SERVER['HTTP_HOST'].'/madison');
That seems to be borne out for some custom 404 handler outside your current .htaccess.
Try adding these lines on top of your .htaccess:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /madison/
And keep your last rule as:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ index.php?action=view&type=page&page=$1 [L,QSA]
Then test this in a new browser to avoid old caches.

.htaccess DirectoryIndex not working

I have a website running on Linux/UNIX but I don’t know a darn thing about the .htaccess file and the syntax used in it..
If you go to http://pr.bananapages.net the system won’t produce any results.
But if you add the file name, it comes up. ex: http://pr.bananapages.net/index.html
NOTE: The URL points to a subfolder on the shared access hosting server but it doen't really matter because when you type in www.bananapages.net/pr/hamshack, (That's where the short cut DNS address points to), It still won't produce the index.html file without actually specifying it.
I have tried everything I could find about DirectoryIndex but I can’t get it to work without using the file name… (index.html)
This is my current .htccess file.
Options -MultiViews
DirectoryIndex system.php index.php
<IfModule mod_rewrite.c>
DirectoryIndex system.php index.php index.html
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)\.(.*)$
RewriteRule ^(.+[^/])$ http://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
# Google sitemap controller
RewriteRule ^sitemap.xml$ tmp/sitemap.xml [L]
RewriteRule ^tmp/sitemap.xml$ tmp/sitemap.xml [L]
RewriteRule ^index.html$ index.html [L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)(\.xml|\.php([0-9]*)|\.tpl|\.phtml|\.ini|\.inc|/)$ system.php?_p=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ system.php?_p=$1 [QSA,L]
</IfModule>
# compresses text, html, javascript, css and xml
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml
AddOutputFilterByType DEFLATE application/javascript application/x-javascript
</IfModule>
NOTE: If I rename the .htaccess file, it will work without specifying the filename, (index.html) so. I am fairly certain there is something in this .htaccess file preventing this from working the desired way.
You can try this:
in all your
RewriteCond %{REQUEST_FILENAME} !-f
Double it as thus, to say to do rewrite only if lt's neither directory, nor file:
Edit
(Tested in Debian/Apache2).
Options -MultiViews
DirectoryIndex system.php index.php index.html
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)\.(.*)$
RewriteRule ^(.+[^/])$ http://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
# Google sitemap controller
RewriteRule ^sitemap.xml$ tmp/sitemap.xml [L]
#RewriteRule ^tmp/sitemap.xml$ tmp/sitemap.xml [L]
#RewriteRule ^index.html$ index.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)(\.xml|\.php([0-9]*)|\.tpl|\.phtml|\.ini|\.inc|/)$ system.php?_p=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ system.php?_p=$1 [QSA,L]
to see if it works better? Please notice some commented infinite loop rewriterule.
I had a similar situation on my vps
I wanted my default homepage to be login.php so if someone where to go to http://[ip]/[folder]/ it would just load the login.php file that I set in my .htaccess within the [folder]
so i set 'DirectoryIndex login.php' in .htaccess but
it would not work instead I would get a 403 when going to http://[ip]/[folder]/ as I didn't have any index.html or index.php
so...
I decided to check the apache config file httpd.conf and under DirectoryIndex I put 'login.php' as part of the list that was already there then restarted the httpd service and
it worked for me!
Here's the answer...
# Rules for subfolders
# for pr.bananapages.net
RewriteRule ^pr/(.*)$ pr/$1 [L]
# for jm.bananapages.net
RewriteRule ^jm/(.*)$ jm/$1 [L]
# and so on....
RewriteRule ^dr/(.*)$ dr/$1 [L]
RewriteRule ^usvi/(.*)$ usvi/$1 [L]
RewriteRule ^bvi/(.*)$ bvi/$1 [L]
RewriteRule ^kitts/(.*)$ kitts/$1 [L]
RewriteRule ^ar/(.*)$ ar/$1 [L]
RewriteRule ^tt/(.*)$ tt/$1 [L]
I don't know why that works but it does seem to work...
Dale

Redirect loop due to htaccess file

The problem I'm having is that the first URL works and the second one doesn't.
http://www.example.com/podcasts
http://www.example.com/podcast
They're both HTML files, so adding .html to the second one will make it work. It's only when the html extension is stripped away (which is what I want to happen) that the redirect problem appears.
I think the issue is that "podcast" is both a folder and an html file. In other words, there is a folder called "podcast" and there is also a file called podcast.html, the extension of which is automatically stripped away (which was my intention).
So how can I fix this redirect issue? I would like the folder and the html to still have the same names and the html extension to be be stripped away, as it is now.
Here's a copy of my .htaccess file (edit: added L flags)
RewriteEngine On
RewriteBase /
#removing trailing slash
RewriteRule ^(.*)/$ $1 [R=301,L]
#non www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#shtml
AddType text/html .html
AddHandler server-parsed .html
#html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
#index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://example.com/ [R=301,L]
Pretty sure that the RewriteRule pertaining to %{REQUEST_FILENAME} !-f is causing the issue. The loop doesn't occur for a 404 error.
Ideas?
Try putting this under your HTML section.
RewriteCond %{REQUEST_FILENAME} !-d
Your -f flag will prevent files from being considered in the rule, but this will exclude directories.