Hey guys, I am a little concerned about something I've been searching for a long time. In a directory in my server I have a .htaccess file containing these lines: RewriteEngine on RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule . - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L] Code (markup): This code makes files that are on the root of the directory to be available if browsed on subfolders... For example http://www.server.com/user1/index.php will output the same as http://www.server.com/index.php. What I am trying to do is to make the code to have some more functionality. I would like the code to be able to mimic files from other directories, not just the root one. Aditionally I would like the code to use the custom directories as a variable. For example http://www.server.com/user1/page.php should output the same in http://www.server.com/secret/ss-page.php?mid=user1. And http://www.server.com/user1/page.php?foo=bar should output the same in http://www.server.com/secret/ss-page.php?mid=user1&foo=bar. Another example: http://www.server.com/user1/more/page.php?foo=bar should output the same in http://www.server.com/secret/more/ss-page.php?mid=user1&foo=bar. Thanks in advance, -AT-XE
This code will direct ALL requests to the file site_mod.php: #activate mod_rewrite Options +FollowSymlinks RewriteEngine on RewriteBase / #rewrite conditions RewriteRule ^(.*)$ site_mod.php?$1 Code (markup): When this code sends the request to your file, you can look at the $_SERVER["REDIRECT_QUERY_STRING"]); variable in FTP to see exactly what URL the user entered. Then, based on the request, you either redirect them or provide them with the data. Here is an example: // The redirect_query string is broken into segments $GLOBALS["page_request"] = explode ("/", $_SERVER["REDIRECT_QUERY_STRING"]); // Requests for files in the theme directory are handled immediately if (strcasecmp ($GLOBALS["page_request"][0], "theme") == 0) { // Since this site uses a global redirect, this module has to handle requests // for files in the theme folder directly $filename = basename ($_SERVER["REDIRECT_QUERY_STRING"]); if (is_file ($_SERVER["DOCUMENT_ROOT"]."/themefiles/".$filename)) { // apparently firefox and chrome are not happy without a mime type for .css if (substr ($filename, -4) == ".css") { header ("Content-Type: text/css"); } readfile ($_SERVER["DOCUMENT_ROOT"]."/themefiles/".$filename); exit; } else { header ("HTTP/1.0 404 Not Found"); exit; } } Code (markup):