Jump to content

Recommended Posts

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?!) :o

 

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.

 

 

I thought my code handled such a scenario?!

 

Glad I caught that when I was testing?!  :o

 

Any idea what is going on?

 

 

Debbie

 

 

Link to comment
https://forums.phpfreaks.com/topic/245406-mod_rewrite-showing-directory/
Share on other sites

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

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.