User friendly URL on specific page

Asked

Viewed 111 times

-2

I am with a customer project in production (Locaweb then n has Cpanel :|) and have a news page and need to leave the same with friendly URL, the page php news. has the following code: How do I leave a page and need to leave it with friendly URL. The page noticia.php, and has the following code:

$urlpath    = $_SERVER['PATH_INFO'];
$urlpath    = $_SERVER['PATH_INFO'];
$paths        = explode('-', $urlpath);
$paths        = explode('-', $urlpath);
$i_item        = end($paths);
$i_item        = end($paths);

It takes the '/title-of-the-news-00', 00 that would be the news ID, need the URL 'http://localhost/noticia.php/titulo-da-noticia-00' can also be accessed by 'http://localhost/noticia/titulo-da-noticia-00'

The .htaccess current is like this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

But when accessing the hosting I get the following error message:

HTTP Error 404.0 - Not Found The Resource you are Looking for has been Removed, had its name changed, or is temporarily unavailable.

1 answer

0


Try this

Arquivo noticias.php

<?php
    $titulo = $_GET['noticia'];
    $id = end(explode('-',$titulo));
    echo $id;
?>

File . htaccess

RewriteEngine On
RewriteRule ^noticia\/(.*)$ noticia.php?noticia=$1

Url

/news/title of news-222

  • I’m still getting error 404, but the logic is right. It was just the plural news, valeuu!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.