Mobile app version of vmapp.org
Login or Join
Jennifer507

: Redirecting all traffic to a script I am on Centos 6.5 with Apache2 and Perl 5.23. I need to pass all traffic to the single perl script, check this request in a database, and show needed

@Jennifer507

Posted in: #Apache #Htaccess #ModRewrite #Redirects

I am on Centos 6.5 with Apache2 and Perl 5.23. I need to pass all traffic to the single perl script, check this request in a database, and show needed content (have both static and dynamic content).

The problem is I don't know how not to get caught to the infinite loop in mod_rewrite.

F.e. first time I pass a request to a script script sees that the user needs a static content and redirects it to the needed page, but this way the user gets to the .htaccess rules again.

I thought to add some kind of a parameter, but not sured. Need your help!

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Jennifer507

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

What you are referring to is a "front controller". The usual first step is to make sure that the resource being requested is not a physical file on the filesystem before rewriting to your front controller (ie. your Perl script).

For example, using mod_rewrite in your root .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ perl-script.pl [L]


This internally rewrites all requests to perl-script.pl (in the document root) providing the requested resource does not map to a physical file or a directory (the two RewriteCond directives are AND'd by default).


I am on Apache/2.2.15


However, if you were on Apache 2.2.16+ (so close!) then it's even easier. There is a mod_dir directive specifically for this:

FallbackResource /perl-script.pl


Reference: httpd.apache.org/docs/2.2/mod/mod_dir.html#fallbackresource

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme