HelpingHand
HelpingHand

Reputation: 1065

Redirect any hit to a non-existent directory to a PHP page

What I want to do

For instance, if a user requests /nonexistentdirectory, how could the hit be redirected to /hits.php?d=nonexistentdirectory ?

How I've tried to do it

I've tried the following code in my apache.conf; however, it is replying with an error code:

<Directory /var/www/>
RewriteEngine On

# No redirect, if file or directory exists
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^([A-Za-z0-9-]+)/?$ link/index.php?a=$1 [L]
</Directory>

Error code:

Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden

All suggestions are appreciated!

Upvotes: 2

Views: 127

Answers (1)

Justin Iurman
Justin Iurman

Reputation: 19016

You must enable FollowSymLinks option as it is said.

<Directory /var/www/>
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]

RewriteRule ^/?([^/]+)/?$ link/index.php?a=$1 [L]
</Directory>

Upvotes: 2

Related Questions