Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with .htaccess

I just started learning how to write htaccess . I got the following code from this page, which redirects everything to an index.php file

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    public/    [L]
    RewriteRule    (.*) public/    [L]
</IfModule>

I understood all lines except ^$ public/ [L] and (.*) public/ [L].What does they mean.To me it looks like some regular epression :).. I know RewriteRule is used for writing rules for redirecting .But what do symbols $ ,(,),., * etc. indicate ?.
When I put these lines to .htaccess I got the following error

enter image description here

But when I comment the 4th line,it is working..ie .the following code is working

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    public/    [L]
    #RewriteRule    (.*) public/    [L]
</IfModule

So what is the problem here?

like image 682
Jinu Joseph Daniel Avatar asked Jan 24 '26 20:01

Jinu Joseph Daniel


1 Answers

i think you are inside rewrite loop like blew:
you rewrite abc.com/anything to abc.com/public and also you are rewriting /public to /public.
maybe you should specify which url must be rewrite . (limit your requests) like this :

RewriteEngine on
RewriteRule    ^$    public/    [NC,L]
RewriteRule    ^index.php(.*)$ public/$1    [NC,L]

rewrites index.php?requests to public/?requests

like image 198
M Rostami Avatar answered Jan 27 '26 14:01

M Rostami