remixdesign remixdesign - 4 years ago 133
PHP Question

Rewrite Rule to map to URL Parameter without extension

I am attempting to use HTACCESS to rewrite the following url:

I would like it rewritten as:

The parameter item_id is to be captured in my php file with the following code:

if (isset($_GET['item_id'])) {
$url_item = $_GET['item_id'];
$urlParmResult = filter_var($url_item, FILTER_SANITIZE_URL);
echo $urlParmResult;
echo "The link you requested does not exist.";

I am using the following .htaccess:

RewriteEngine On
RewriteRule ^([^/]*)$ index.php?item_id=$1 [L]

however all i get returned on the page is:


Can someone please help me out? What am I doing wrong here?

Answer Source

You can use:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ index.php?item_id=$1 [L]

Which eliminates existing files or directories, to avoid redirect index to index

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download