Forum Moderators: phranque

Message Too Old, No Replies

^i(.*)$ works but ^(.*)$ doesn't

why is the first character so imp

         

AjiNIMC

11:37 am on Dec 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule ^i(.*)$ /members/index.html works and shows /members/index.html content for index.html but when I write

RewriteRule ^(.*)$ /members/index.html , it doesnt work and gives Internal server error.

What can be the possible error? I have not posted it with the other question as it looks different from the other problem.

Please help.

Thanks to everyone, Happy Xmas too
AjiNIMC

jdMorgan

4:29 pm on Dec 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The most likely cause of the server error is that you've defined an infinite loop. You need to explicitly tell mod_rewrite when to rewrite and when not to rewrite. So if you tell it to rewrite *everything* to /index.html, then it will also rewrite /index.html to /index.html -- creating an infinite loop.

# if NOT already rewritten to /members/index.html
RewriteCond %{REQUEST_URI} !^/members/index\.html$
# rewrite all requests to /members/index.html
RewriteRule (.*) /members/index.html [L]

should work better.

You should also be aware that you will rewrite robots.txt and all image, CSS, and external JS files to /members/index.html with this code, so think about what classes of files you really want to rewrite, and which you don't. Then you can write a rule-set based on whichever class is smaller or easier to define.

Jim

AjiNIMC

5:53 pm on Dec 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



actually this is more related with cache systems and we want to disable cache systems if the user is logged in.

This is not going to infinite loop as firefox tells you if the redirection happens for more than a specified number.

I am also not using [R](redirect) so REQUEST_URI wont work as a check, I will have to check with Script_URI.

I am going to try this after christmas. A very happy Christmas to all webmastermaster members.

Special thanks to jdMorgan for the replies

jdMorgan

5:59 pm on Dec 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I am also not using [R](redirect) so REQUEST_URI wont work as a check, I will have to check with Script_URI.

Erm... Don't confuse REQUEST_URI with THE_REQUEST. REQUEST_URI works fine to stop internal rewrite looping.

> This is not going to infinite loop as firefox tells you if the redirection happens for more than a specified number.

But of course, Firefox isn't involved here, since this is an internal rewrite loop, not a redirection loop.

Check your error logs...

Jim

AjiNIMC

4:30 pm on Dec 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wow it worked. Thanks a lot Jim for the help.

Will this make any significant change in page loading time?

jdMorgan

6:11 pm on Dec 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Significant? - No, you should not notice any difference until you get over a hundred thousand hits a day.

Since it is an internal rewrite, you don't have the factor of the network time needed to tell the client to re-request the object, and for the client to do so.

Jim

AjiNIMC

1:01 am on Dec 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Jim for the help.

Regards,
Aji

AjiNIMC

8:49 am on Dec 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need one more help.

How do I check whether the DirectoryIndex REQUEST_URI is a folder or not.

AjiNIMC

9:17 am on Dec 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Now it is working,

I had to do this,

RewriteCond %{HTTP_COOKIE} ([[:print:]])userid([[:print:]])
# if NOT already rewritten to /members/index.html
RewriteCond %{REQUEST_URI}!^/members/index\.html$
# rewrite all requests to /members/index.html
RewriteRule (.*) /members/index.html [L]
RewriteCond %{HTTP_COOKIE} ([[:print:]])userid([[:print:]])
# if it is a directory
RewriteCond %{REQUEST_FILENAME} -d
# rewrite all requests to /members/index.html
RewriteRule (.*) /members/index.html [L]

Is there a better way I can use the [OR]

Thanks
Aji

jdMorgan

11:37 pm on Dec 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, try it and see...

RewriteCond %{HTTP_COOKIE} ([[:print:]])userid([[:print:]])
# if NOT already rewritten to /members/index.html
RewriteCond %{REQUEST_URI}!^/members/index\.html$ [OR]
# or if request exists as a directory
RewriteCond %{REQUEST_FILENAME} -d
# rewrite all requests to /members/index.html
RewriteRule (.*) /members/index.html [L]

Jim