Question

I'm currently writing a cms system in a subdirectory of the main html root and was wondering is possible using htaccess to redirect all requests that come from say /cms/ to use /cms/ as it's root directory.

e.g: example.com/cms/index.php calls the following code

<script type="text/javascript" src="/lib/js/jquery.js"></script>
<?php require($_SERVER['DOCUMENT_ROOT']."/lib/php/header.php"); ?>cu

and in return fetches:
   example.com/cms/lib/js/jquery.js
   example.com/cms/lib/php/header.php

Was it helpful?

Solution

Add this to your .htaccess in your web root / directory

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteCond %{DOCUMENT_ROOT}/cms%{REQUEST_URI} -f [NC]
RewriteRule ^(.*)$ cms/$1 [L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top