htaccess with friendly url not working(?)

Asked

Viewed 150 times

1

I’m finishing a project, and I thought I’d put a user-friendly URL, one I had already used in another project, the same thing, I didn’t change anything, just the server and site host.

Of: www.site.com/noticia?id=1 for www.site.com/noticia/1 however, it is adding a "/" at the end of everything (www.site.com/noticia/1/), what is giving the page "NOT FOUND".

In the other project that I mentioned above, it is the same, same code, I only changed the information that will fetch and return from the page that displayed the content, but the last "/" is giving the conflict, and I have no idea how to remove it.

I looked in several sites to see if you find any way to remove or even other that did the same thing, however, unsuccessfully, I searched here too and nothing.

I just don’t know if the host has any influence on this, since I don’t usually mess around with . htaccess.

In wamp it runs correctly, even without the . htaccess, however, on the host of this problem.

The . htaccess is like this

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1.php/$2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
ErrorDocument 403 //403.php
ErrorDocument 404 //404.php
ErrorDocument 500 //500.php

The Code of the display page:

<?php 
include_once "assets/inc/head.php"; 
include_once "assets/inc/busca.php";
$Carro =  $_SERVER['PATH_INFO'];
$CarroN = $_SERVER['PATH_INFO'];
$CarroL = $_SERVER['PATH_INFO'];
$CarroF = $_SERVER['PATH_INFO'];
$muda_path = explode('/', $Carro );
$muda_path = explode('/', $CarroN );
$muda_path = explode('/', $CarroL );
foreach($muda_path as $carro_link){
    $CarroID = $carro_link;
    $CarroNome = $carro_link;
    $Carro_Link = $carro_link;
    $video_select = "SELECT * FROM carros WHERE `id`='$CarroID' OR `link_carro`='$Carro_Link' OR `nome_carro`='$CarroNome'";
    $query = @mysql_query($video_select) or die (mysql_error());
}
if (mysql_num_rows($query) <= 0) {
    $vd = mysql_fetch_assoc($query);
    include_once "assets/inc/not_found.php";
    };?>

I’m still kind of new to programming since I move more with html and css, so the code might be kind of amateur.

1 answer

0


I usually use the following

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^noticia(|/)$ noticia.php
RewriteRule ^noticia/(.*)$ noticia.php?id=$1

I use in my host and never presented me problems.

  • thanks @VME, it seems that it worked, removed the last bar, but now I discovered also the file is not catching the $_SERVER['PATH_INFO'] of the link without the .php of the news. Any suggestions?

  • I already solved the problem, I just switched to $_SERVER['REQUEST_URI'] and now it worked. Thanks for the help!!

  • Oops. I’m glad you made it. I could only go in now. !

  • I’m new to Stack, and I don’t have enough reputation ://

Browser other questions tagged

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