Jinu Joseph Daniel
Jinu Joseph Daniel

Reputation: 6291

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?

Upvotes: 3

Views: 186

Answers (2)

M Rostami
M Rostami

Reputation: 4195

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

Upvotes: 1

Jesse the Game
Jesse the Game

Reputation: 2628

This is an answer to your first question, for the second, you should provide us with more information (like a log entry from /var/log/apache2/error.log)

^ matches the beginning of a string

$ matches the end of a string

^$ matches an empty string

. matches any character

* allows 0 to any number of occurrances of the preceding match

( and ) mark a group that can be referenced later

(.*) will match any number of characters

Upvotes: 1

Related Questions