matthutaff
asked on
RewriteRule subdirectory creation
I have a number of departments I need to categorize using mod_rewrite. Several departments have full websites with their own subdirectories of information, while others have only a template of information that is generated from a dynamic PHP page. I would like these templates, when served however, to look like they are in their own subdirectory. For example:
/department/smith - this directory exists, so the link going to the Smith department connects automatically to this directory
/department/jones - this directory does NOT exist, so it is created using mod.rewrite and department.php, which is sitting in the /department/ folder.
My .htaccess file is set as follows:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /department/
RewriteRule ^([^.]+)\$ department.php?url_only=$1
</IfModule>
url_only is the database field that forces the recordset's clean URL entry.
Can this be achieved? If so, how?
Thanks.
/department/smith - this directory exists, so the link going to the Smith department connects automatically to this directory
/department/jones - this directory does NOT exist, so it is created using mod.rewrite and department.php, which is sitting in the /department/ folder.
My .htaccess file is set as follows:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /department/
RewriteRule ^([^.]+)\$ department.php?url_only=$1
</IfModule>
url_only is the database field that forces the recordset's clean URL entry.
Can this be achieved? If so, how?
Thanks.
ASKER
Just the execution/writing of the RewriteRule, really.
.htaccess in the department folder
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /department/
RewriteRule ^department/([^/]*)/? department.php?url_only=$1
it would let you access existing files and folders but a call to something that doesnt exist like
/department/jones
/department/jones/
/department/jones/wholehea pojunk
will redirect to
/department/department.php ?url_only= jones
the rewrite rule
RewriteRule ^department/([^/]*)/? department.php?url_only=$1
says is looking for any non '/' characters ( [^/]* ) that occur between 'department/' and and optional '/'
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /department/
RewriteRule ^department/([^/]*)/? department.php?url_only=$1
it would let you access existing files and folders but a call to something that doesnt exist like
/department/jones
/department/jones/
/department/jones/wholehea
will redirect to
/department/department.php
the rewrite rule
RewriteRule ^department/([^/]*)/? department.php?url_only=$1
says is looking for any non '/' characters ( [^/]* ) that occur between 'department/' and and optional '/'
ASKER
Hi,
I've tried the solution and it's not registering the department.php file. A 404 error appears when you try to visit the jones department. Does the parh for department.php need to be identified?
I've tried the solution and it's not registering the department.php file. A 404 error appears when you try to visit the jones department. Does the parh for department.php need to be identified?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The basic theory of what you are trying to acheive is sound.