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

有帮助吗?

解决方案

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]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top