top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

rewrite rule on apache2 .htaccess file

0 votes
254 views

I have problems making successfully a rewrite rule for my Webapplication (CodeIgniter) with mod_rewrite.

In my ".htaccess" file, I have the following rewrite rules:

RewriteEngine on
RewriteRule ^[css|js|fonts](/.*)?$ /static$1 [L]
RewriteRule ^(.*)$ /index.php/$1 [L]

But the 1st rule doesn't work, neither I know if the rule was correct.

I want first:

/css/* -> /static/css/*
,/js/* -> /static/css/*
/fonts/* -> /static/fonts/*

and anything else

/index.php/

The second rule seems to work. But the 1st rule makes me headache.

posted Jul 21, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

First rewrite doesn't match because regex is wrong. The URL your rewrite should match is something like this:

/css/path/filename.css

so your regex should first match the first / character. Then, don;t confuse alternation with a character class. If you want express an alternation you need a group, it means rounded brackets instead of square brackets.

Last but not least, the second rewrite doesn't match the first / too, I suppose it worked because even if the slash is doubled the PHP code, in some way, will handle it. Honestly, after all I had no time to test my suggestion, but please try with this:

RewriteRule ^/(css|js|fonts)(/.*)?$ /static$2 [L]
RewriteRule ^/(.*)$ /index.php/$1 [L]
answer Jul 21, 2013 by anonymous
Similar Questions
+2 votes

I encounter problems to rewrite a rule
The page /cgi-bin/blt?action=cs_query is now gone and I would like to notify this.

I tried the following thing without success.

RewriteEngine on
RewriteRule ^/cgi-bin/blt?action=cs_query$ - [G]

An suggestions?

+1 vote

what is the location of .htaccess file in apache. I tried searching for it find . -name ".htaccess" but returns no result

0 votes

I really don't understand some things about htaccess. Reading, the advice is: never permit htaccess to users. So, can I enable htaccess but only for personalize something like this?

ErrorDocument 400 /errors/badrequest.html
ErrorDocument 401 /errors/authreqd.html
ErrorDocument 403 /errors/forbid.html
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/serverr.html

and obviously deny all other directives? so an user with own htaccess file, can only personalize that directives.

+1 vote

I've two machines set up with Apache2.4 and PHP5.4.15 and I'm trying to debug owncloud as it has problems with Apache2.4. This autoloader and routing 'fun' seems totally over the top, and is failing without giving any errors, but the question is "what limits the amount of text displayed using print_r() ?" Where I drop in a print statement causes crashes, but when working I'm not getting a complete printout. One machine is clipping at around 4500 characters, while the other is managing around 9000, and neither is displaying the 'TAG' labels after that block.

It's not something I've seen before ... I've been using this method for many years and normally see all the text. So can anybody throw light on why this may be happening now? Interestingly the two machines are giving different problems with this application which works correctly on Apache 2.2

...