Quite Simple :)

New to mod_rewrite? This is a good place to start.

Quite Simple :)

Postby MaZderMind » Wed Sep 29, 2004 1:09 pm

It seems to be Quite Simple

http://.../here/gose/any.thing
turns to
http://.../allocator.php?here/gose/any.thing

I simply wrote

Code: Select all
RewriteEngine on
RewriteRule ^(.*)$ allocator.php?$1

but all I received in allocator.php was 'allocator.php'.

wenn I instead tried
Code: Select all
RewriteRule ^(.*).$ allocator.php?$1

with a dot, i got the right adress but missing the last char. Why doesn't my first RegEx work as expected..

Thanks for your Help,
Peter aka MaZderMind
MaZderMind
 

Solved

Postby mazdermind » Wed Sep 29, 2004 2:32 pm

Solved the Problem on my opwn - it isent that hard if you once understood it ^^

Peter
mazdermind
 

Postby Napalm » Thu Sep 30, 2004 5:02 pm

Don't forget to share the answer with us :)
Napalm
 
Posts: 2
Joined: Thu Sep 30, 2004 5:01 pm

Solution

Postby MaZderMind » Fri Oct 01, 2004 5:54 am

If you think it could be useful :)

When the first request is rewritten to 'allocator.php?...',the new request is, too, parsed over the rewrite-rule. becouse of the rewrite ignores everything after and including a '?' in the requested uri, the uri the rewriter is called with the url './allocator.php?./allocator.php', what is rewritten to './allocator.php?./allocator.php' what is rewritten... so there should be an infinite loop. but the rewriting-engine stops such a loop after a certain loops (by default 10). so after 10 loops the url is finally passed through - with './allocator.php' passed tho the allocator.
You can see this writing an rewritelog by specifying sth. like

Code: Select all
RewriteLog d:/www/_logs/www.dynacms.home.rewrite.log
RewriteLogLevel 9


in your apache-config (it wont work in an .htaccess and produce an 500-Error)

So what to do?

Its as simple as the problem seemd to be: set a Rewrit-Condition.

In this case that means:
Code: Select all
RewriteCond %{REQUEST_URI}  !.*allocator.php$
RewriteRule ^(.*)$  "./_compiler/allocator.php?$1" [L]


But then i got another problem: i got two directories ('_admin' and '_dynamic') i want to leave out from beeing rewritten. The solution for this? write two other Contitions like this:

Code: Select all
RewriteCond %{REQUEST_URI}  !.*allocator.php$
RewriteCond %{REQUEST_URI}  !_admin.*
RewriteCond %{REQUEST_URI}  !_dynamic.*
RewriteRule ^(.*)$  "./_compiler/allocator.php?$1" [L]


And well - it works.
Another benefit - calls to any file (except allocator.php, of course) under './_compiler/', where some internal scripts are placed, are redirected to the allocator, too.

Hope it helps some other beginners like me,
Peter
MaZderMind
 


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 96 guests

cron