Mobile app version of vmapp.org
Login or Join
Vandalay111

: .htaccess two different rules but only one per time I'm rather new to the whole .htaccess thing and I'm using the following right now to use 'pretty url's': <IfModule mod_rewrite.c>

@Vandalay111

Posted in: #Htaccess #ModRewrite

I'm rather new to the whole .htaccess thing and I'm using the following right now to use 'pretty url's':

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?path= [NS,L]
</IfModule>


Now i found my website a bit slow and decided to start gzipping my CSS files thru a php script I found somewhere on the web (the website). For this to work I need to rewrite the url to open the correct php file. That would look something like this:

RewriteRule ^(.*).css$ /csszip.php?file=.css [L]


But I only want the first to happen when the second doesn't and vice versa. In other words i'd like something like this:

<IfModule mod_rewrite.c>
RewriteEngine On
if request doesn't contain .css do
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?path= [NS,L]
else do
RewriteRule ^(.*).css$ /csszip.php?file=.css [L]
</IfModule>


Can anyone help me with the proper code or a place where i can find a way to use some kind of conditional statement in htaccess files?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Vandalay111

2 Comments

Sorted by latest first Latest Oldest Best

 

@Deb1703797

You should not do this, use Apache deflate module to Gzip you files. This is what I use in .htaccess :

<IfModule deflate_module>
AddOutputFilterByType DEFLATE text/php text/html text/txt text/javascript text/css application/javascript application/x-javascript
</IfModule>


Check out the documentation to have more info on the mime type and the syntax : httpd.apache.org/docs/2.2/mod/mod_deflate.html

10% popularity Vote Up Vote Down


 

@Jessie594

I will go onto something like that.

First you define a new condition (RewriteCond) then you apply this condition using a rule (RewriteRule).

Thanks to the flag L at the end of the RewriteRule, this stop the rewriting process immediately and don't apply any more rules. So when the request is a .css file, the first rule will be apply and not the second one. For all others request, it won't match the first condition, then go to the second one.

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} ^(.*).css$
RewriteRule ^(.*).css$ /csszip.php?file=.css [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?path= [NS,L]
</IfModule>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme