Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite directory

New too mod_rewrite

         

Sibertank

1:32 am on May 3, 2006 (gmt 0)

10+ Year Member



Hey guys, I’m pretty new too mod rewrite and I had a question. Lets say I have a website (www.site1.com for example) and I wanted all my files on that website to be under the directory /Public/ so it would be www.site1.com/Public/ and the entire site would be their. I could use a PHP Header redirect to send people typing in www.site1.com to www.site1.com/Public but I want to make it look nice and have them silently redirected to the Public directory. I believe that this can be done using mod_rewrite. I have been able to get it to silently redirect to /public/ but once I click a link to say go to www.site1.com/Tutorials (www.site1.com/Public/Tutorials), it will give me a 404. Shouldn’t it still silently be redirecting too /public/?

IamStang

11:37 am on May 4, 2006 (gmt 0)

10+ Year Member



I could be wrong but would the following not work?

RewriteRule ^/(.*)$ /Public/$1

Might need some tweeking, but is that not the principle? Still learning this part of Apache myself and kinda wondering if I am correct.

Thanks!
(basicaly, was gonna ask just about the same question. LOL)

Sibertank

2:50 am on May 5, 2006 (gmt 0)

10+ Year Member



I actualy figured it out and its kinda weird, its on that basic concept that you have their but a llittle different.

RewriteCond %{REQUEST_URI}!^/Public/
RewriteRule ^(.*)$ /Public/$1 [L]

Without the RewriteCond it will just spit back a 500. I understand what the condition rewrite dose but Im not sure why it has to be their for this to work, mabey some one could fill me in :)

jdMorgan

3:12 am on May 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Without the RewriteCond the rule will loop, since it rewrites *any* requested URI -- including previously-rewritten ones. So it will happily continue rewriting your request again and again until the server hits its preconfigured internal redirection limit, at which point, your error log will show that the server gave up and generated a 500-Server Error - Maximum internal redirection limit reached. (Make friends with your error log, it's quite useful.)

In the .htaccess context, access-control processing will restart once any rewrite is invoked. The server will re-process the mod_alias, mod_proxy, mod_access, and mod_rewrite (and some other) directives in httpd.conf, conf.d, and in all the .htaccess files 'along the way' to the resource (file) specified by the new URL. This is to make sure that the new URL does not resolve to a file that needs password authorization or that has some other access restrictions on it. This makes mod_rewrite execution appear to be recursive, and causes loops if you don't explicitly prevent them. But since it also makes your server harder to hack, it's a good thing.

Jim

Sibertank

4:14 am on May 6, 2006 (gmt 0)

10+ Year Member



Thanks for explaning it Jim! Yeh I was checking out my error log, was a nice way to see exactly what was going on.

Thanks again for the info!