htaccess code for css & js url rewriting not working - .htaccess

i am implementing following solution for cache problem:
How to force browser to reload cached CSS/JS files?
but browser not able to found my css file after change it's name.
when i manually goes to open it, it gives 404 error.
here is my complete .htaccess code:
RewriteEngine on
RewriteBase /App
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]
RewriteRule ^(.*)\.[\d]{10}\.(css|js)$ $1.$2 [L]
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
My css file path is:
/assets/master.css
basically what i want to do is dynamically rewrite all css & js files like this: master.1454667174.css to this: master.css
i want server to ignore that 10 digit number before file extension and return only master.css file to browser.
Please help..

url rewriting should affects your file path. You have to put a '/' to the css or js file path.
Example:Your Original file path -> css/style.css
You have to do -> /css/style.css
this is as same as for js and image path..
(or)
you have to put the base url link in your head tag
https://www.w3schools.com/tags/att_base_href.asp
refer this to get the base url html syntax

Related

Organize root directory using htaccess - urls without extensions and without https

I am trying to organize the root directory of my site, because I am gonna create a big number of files in it, so I am using .htaccess to help me to do it but my command isn't dynamic and I need to create another line every time when I create a new file.
This is the code of my .htaccess:
RewriteEngine On
#Force request to HTTP
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ http://www.example.com.br/$1 [R=301,L]
#Redirect the request of file inside folder 'teste' to base URL - HERE IS THE RULE WHICH ISN'T DYNAMIC
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com.br
RewriteRule ^file2 directory/file2.php [L,QSA]
#Hide and Redirect Extension
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteRule ^(.+)\.php$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/shtml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
When I request for this URL: http://www.example.com.br/file2 I can read the content of the file called file2.php which is located in this path: http://www.example.com.br/directory/teste2.php everything working perfect but I am gonna put 11k of files inside this folder (http://www.example.com.br/directory/) and I cant create a new rule in .htaccess for every page, I know there is a form to create the command dynamically, but I tried with no luck.
How do I do it dynamically?

301 Redirect in the HTACCESS working for all but a few pages

So, I'm working on a site with 2 domains that are both hosted out of the same directory on the same server (It has Wordpress installed if that is important). I want to 301 redirect all the pages from oldname.com to newname.com with the same path. I have edited the HTACCESS and all but 3 pages are redirecting, but I can not find out why they are not redirecting.
Here's the code that I have to redirect, it checks the host and if it is not newname.com then it redirects to newname.com and maintains the path.
RewriteCond %{HTTP_HOST} !newname.com$ [NC]
RewriteRule ^(.*)$ http://newname.com/$1 [R=301,L]
There's also a bit more code in the HTACCESS that was there before I added mine, I'll post it just in case it ends up being important.
# 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
<IfModule deflate_module>
<IfModule filter_module>
AddOutputFilterByType DEFLATE text/plain text/html
AddOutputFilterByType DEFLATE text/xml application/xml application/xhtml+xml application/xml-dtd
AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml image/svg+xml
AddOutputFilterByType DEFLATE text/css text/javascript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE font/otf font/opentype application/font-otf application/x-font-otf
AddOutputFilterByType DEFLATE font/ttf font/truetype application/font-ttf application/x-font-ttf
</IfModule>
</IfModule>
Here are the pages that aren't working (they should redirect to Irklaw.com/path):
http://muskokaattorneys.ca/home-commercial-real-estate-muskoka/
http://muskokaattorneys.ca/the-team
http://muskokaattorneys.ca/new-look
Any help is greatly appreciated, thanks!

What is causing my site to load and add "#" at the end?

I think there might be something in my .htaccess file that is causing my page to load and then "bounce" back to the top adding # at the end of my domain, like this: example.com/#
Here is my htaccess file:
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Start Category Redirects
Redirect permanent /check-out-this-page-tration http://example.com/this-page/
Redirect permanent /rewards http://example.com/example-reward-coupons-page/
Redirect permanent /p-photo-entries http://example.com/2012-contest-photos/
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
# END WordPress
Any ideas on what I should remove or change?
URL fragments are used by the client (a web browser) to help determine how to handle the content that it's trying to display.
This can be anchors to jump to a certain part of a page, or used by javascript to send information between other scripts. This is not your htaccess file as fragments are never sent to the server (where your htaccess file lives).
Try selectively removing javascript (especially scripts that you load from 3rd party sites that share links like "Add To Any"), otherwise make sure you have no links in your content that look like this:
some/path/file.html#

ErrorDocument is not working for 401 response

I am trying to redirect to a custom error page using a redirect in .htaccess. Please check the site jobslanda.com. The line ErrorDocument 401 401.php is not working. I am using the following configuration in .htaccess:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/([\w.,]+)/([\w.,]+)/([\w.,]+)/([\w.,]+)/([\w.,]+)/([\w.,]+)$ job.php?j=$1
RewriteRule ^([a-zA-Z0-9]+)/([\w.,]+)/([0-9]+)$ sameIndustryJobs.php?i=$1&c=$2&p=$3
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([\w',]+)/([0-9]+)$ sameCatagoryJobs.php?c=$1&s=$3&p=$4
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([\w.,]+)/([0-9]+)$ sameCityJobs.php?c=$1&cn=$4&p=$5
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([\w.,]+)/([0-9]+)$ sameQualificationJobs.php?q=$1&cn=$5&p=$6
ErrorDocument 401 401.php
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
Is it because you did not spell ".htaccess" correctly? (And your Apache installation is not picking up the file?)
Where do you have the 401.php file located on your web server? Typically the ErrorDocument directive should begin with a / and reference a page relative to your web root.
Reference:
http://httpd.apache.org/docs/2.0/mod/core.html#errordocument
You don't appear to have a page at:
http://jobslanda.com/401.php
Oddly, that's returning a 302 redirect to a page called 404.php.

htaccess 401 redirect is not working properly

I am trying to write an htaccess code to redirect to a specific page. But it is not working now. Please see the full htaccess code
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/([\w.,]+)/([\w.,]+)/([\w.,]+)/([\w.,]+)/([\w.,]+)/([\w.,]+)$ job.php?j=$1
RewriteRule ^([a-zA-Z0-9]+)/([\w.,]+)/([0-9]+)$ sameIndustryJobs.php?i=$1&c=$2&p=$3
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([\w',]+)/([0-9]+)$ sameCatagoryJobs.php?c=$1&s=$3&p=$4
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([\w.,]+)/([0-9]+)$ sameCityJobs.php?c=$1&cn=$4&p=$5
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([\w.,]+)/([0-9]+)$ sameQualificationJobs.php?q=$1&cn=$5&p=$6
ErrorDocument 401 sorry.php
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
You should put [L] at the end of every RewriteRule line you have. Flag L means Last which indicated end of a rule to Apache.

Resources