0

I have been trying to find a method to redirect all directories except a few to a file with a variable

Example:

site.com/test -> index.php?a=test

I want all subdirectories to be forwarded except for the following

/images
/admin
/includes

I have tried the following withough success.

RewriteCond %{REQUEST_URI} !^/images(/|$)
RewriteCond %{REQUEST_URI} !^/admin(/|$)
RewriteCond %{REQUEST_URI} !^/includes(/|$)
RewriteRule ^([\w/]*)$ index.php/?a=$1 [L]

Is there a way to complete this using .htaccess

EDIT:

I found this which is closer to what im looking for but it needs to be updated to allow access to /images /admin /includes.

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?a=$1  [NC,L,R=301]
Douglas Cottrell
  • 271
  • 2
  • 5
  • 13

1 Answers1

0

In .htaccess you can use this rule

RewriteEngine On
RewriteRule !\.(js|jpeg|ico|gif|jpg|png|css|xml|html|swf|zip|tar|pdf|flv|gz|wmv|avi|rar|mp3)$ index.php [L]

In your application you can get $_SERVER["REQUEST_URI"] and manipulate as you whish!

<?php
$route = explode('/', $_SERVER['REQUEST_URI']);
print_r($route);
Ragen Dazs
  • 2,115
  • 3
  • 28
  • 56