htaccess does not load CSS with second parameter

0

Hello. I have broken my mind to try to solve a problem that should be very simple, but it is not working.

My site is navigated as follows in htaccess localhost/ProjetoBusca/index.php?pg=anuncio being replaced with localhost/ProjetoBusca/anuncio . So far it works perfectly. The problem is that I need a secondary GET, where the ideal would be to transform localhost/ProjetoBusca/index.php?pg=anuncio&n=354 being replaced with localhost/ProjetoBusca/anuncio/354

For this, in my htaccess I developed:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\/(.*)$ index.php?pg=$1&n=$2 [NC]
RewriteRule ^(.*)\/(.*)/$ index.php?pg=$1&n=$2 [NC]

When I work with / ad on the site (as quoted above) everything works fine, the problem is that when I call / ad / 354 I get the get of the n variable, but the full page CSS does not load. What could be happening?

Follow the index.php code:

<html>
    <head>
        <?php   include("view/header.php"); ?>
    </head>
    <body>      

        <?php      

            include("view/topbar.php");
            include("view/navbar.php");

            if(isset($_GET['pg'])){
                $url = $_GET['pg'];                                     

                if(!file_exists("$url.php")){
                    include("home.php");
                }else{
                    include("$url.php");
                }
            }else{
                include("home.php");
            }

            if(isset($_GET["n"])){
                echo "foi instanciado n: ".$_GET["n"]; //para fins de teste
            }

            include("view/rodape.php");
            include("view/copyright.php");
            include("view/scripts.php");?>
    </body>
</html>

Could anyone help me?

NOTE: include with view / ... is because they are in another same folder.

    
asked by anonymous 18.01.2017 / 13:44

1 answer

2

Well, this is a fairly common problem when using urls amigáveis , there are several ways to solve it, the most basic would be to request your css with an absolute link:

<link href="http://www.meusite.com/css/style.css" rel="stylesheet">

There are more dynamic ways to do this, to get the url from the site:

<?php define('SITE_URL', ' http://localhost/ProjetoBusca'); ?>

Then to get this url you would use:

<link href="<?php echo SITE_URL; ?>/css/style.css" rel="stylesheet">

You can also use $_SERVER to search for this url:

$baseUrl = dirname($_SERVER['PHP_SELF']).'/';

Source: stackoverflow in English

You can also use a base tag :

<base href="http://www.meusite.com/" />
<link rel="stylesheet" href="style.css" type="text/css" />

Either way you will have to have an absolute path to order.

Source: link

    
18.01.2017 / 13:53