doubledee Posted August 22, 2011 Share Posted August 22, 2011 I am having an issue where when my Article is deleted from the URL, mod_rewrite (or something) is displaying a directory?! (I didn't know that was possible?!) Here is my mod_rewrite... RewriteEngine on #PRETTY: articles/postage-meters-can-save-you-money #UGLY: article.php?title=postage-meters-can-save-you-money RewriteRule articles/([a-zA-Z0-9_-]+)$ article.php?title=$1 article_index.php <!-- Summary #1 --> <div class="summary"> <h2>Postage Meters Can Save You Money!!</h2> <p class="image"> <a href="<?php echo WEB_ROOT; ?>articles/postage-meters-can-save-you-money"> <img src="<?php echo WEB_ROOT; ?>images/postage_meter.jpg" width="200" /> </a> </p> </div> article.php if (isset($_GET['title'])){ // Title in URL. // Set Article Title. // Build query. // Prepare statement. // Bind variable. // Execute query. // Transfer result set from prepared statement. // Check for Article Record. if (mysqli_stmt_num_rows($stmt)==1){ // Article was Found. $articleExists = TRUE; }else{ // Article NOT Found. // Take user to Home Page. header("Location: " . WEB_ROOT . "index.php"); }// End of CHECK FOR ARTICLE IN DB. }else{ // No Title in URL. // Take user to Home Page. header("Location: " . WEB_ROOT . "index.php"); }// End of CHECK FOR ARTICLE IN URL. If I delete out the "pretty URL" (article portion) then the ARTICLES directory is displayed which is a major security issue, although on my web host I don't think that would happen. http://local.dev3/articles/ I thought my code handled such a scenario?! Glad I caught that when I was testing?! Any idea what is going on? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/245406-mod_rewrite-showing-directory/ Share on other sites More sharing options...
cags Posted August 25, 2011 Share Posted August 25, 2011 The Rewrite rule you have shown does not match the REQUEST_URI /articles/. What you are seeing is nothing to do with mod_rewrite. You are requesting a path to a directory on the server so your server is doing what it's obviously configured to do and showing it's contents. If you don't want this to happen you need to disable indexes. Options -Indexes Quote Link to comment https://forums.phpfreaks.com/topic/245406-mod_rewrite-showing-directory/#findComment-1261743 Share on other sites More sharing options...
doubledee Posted August 25, 2011 Author Share Posted August 25, 2011 The Rewrite rule you have shown does not match the REQUEST_URI /articles/. What you are seeing is nothing to do with mod_rewrite. You are requesting a path to a directory on the server so your server is doing what it's obviously configured to do and showing it's contents. If you don't want this to happen you need to disable indexes. Options -Indexes Do I put that in my .htaccess file in the web root? Thanks, Debbie Quote Link to comment https://forums.phpfreaks.com/topic/245406-mod_rewrite-showing-directory/#findComment-1261943 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.