url friendly rewriting

Asked

Viewed 147 times

1

Hello, all right?

I need my homepage url to look like this: http://meusite.com.br the home page url is appearing like this: http://meusite.com.br/? sourceId=78902565&categoryId=5

A second page appears as the initial: http://meusite.com.br/? sourceId=78902565&categoryId=5

I’d like the second page to look like this: http://meusite.com.br/super-ofertas ie, I would like to hide the sourceId=78902565 and on the site of categoryId=5 appeared super-offers.

On all other pages appears the sourceId=78902565, I would like to hide it in a way that does not harm my sales and in the place of categoryId appear the names of the respective categories, as:

http://meusite.com.br/? sourceId=78902565&categoryId=10 http://meusite.com.br/? sourceId=78902565&categoryId=20

I wish you’d show up:

http://meusite.com.br/celulares http://meusite.com.br/tv

My . htaccess is like this:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

</IfModule>

My index.php looks like this:

<?php
     function getHome(){
    $url = (isset($_GET['url'])) ? $_GET['url']: ('home');           
        $url = array_filter(explode('/',$url));         
        $file = ('pgs/'.$url[0].'.php');

        if(is_file($file)){
               include $file;
        }else{ 
               include('pgs/'.'home'.'.php'); 
        };

        if((null== $file) || ('pgs/'.$url[0].'.php')== '' || ($_GET['url']) === false){
           include('pgs/'.'404'.'.php');  
               exit();      
        };       

     };
     getHome();
?>

Other pages like: contact and about work normally, only for the precise url(s) friendly offers page.

Is fix those weird url(s) that appear?

From now on I thank you for your help.

  • see if it works, RewriteRule ^sourceId\/([0-9]{8})\/([0-9]+)\/?$ [NC] /?sourceId=$1&categoryId=$2

1 answer

-1

Ogirinal url:

http://meusite.com.br/?sourceId=78902565&categoryId=10

Rewritten url:

http://meusite.com.br/categoryId/10

Rule:

RewriteRule ^categoryId/([^/]*)$ /?sourceId=78902565&categoryId=$1 [NC]

to leave in this format:

http://meusite.com.br/celulares

your url would need to be http://meusite.com.br?category=celulares

your url needs to receive the category by name and not through the number as this currently:

http://meusite.com.br/?sourceId=78902565&categoryId=celulares

To add the sourceId just change it this way:

RewriteRule ^([^/]*)/categoryId/([^/]*)$ /?sourceId=$1&categoryId=$2 [NC]

Original url: http://meusite.com.br/?sourceId=78902565&categoryId=10

Rewritten url: http://meusite.com.br/78902565/categoryId/10

  • Hello Hebert, all right? I tried Rewriterule sourceId/([0-9]{8})/([0-9]+)/? $ [NC] /?sourceId=$1&categoryId=$2 and gave error 500. The Rewriterule categoryId/([ /]*)$ /?sourceId=78902565&categoryId=$1 [NC]&#Xa does not load the offers from Brazil. Would you have any other solution to improve these urls? Thanks in advance.

  • you want the url so? http://meusite.com.br/78902565/celulares?

  • Hello Hebert, all right? I’d really like to hide the number 78902565(sourceId). There would be some other way that maybe it wasn’t htaccess, ie, some programming code in php or html that could hide the sourceId and the site works, normally, and the url look like this: http://meusite.com.br/cellulares? Thank you very much for your dedication in solving my problem.

  • hello, that rule RewriteRule ^categoryId/([^/]*)$ /?sourceId=78902565&categoryId=$1 [NC] you said it didn’t work the offers? when you say "offers do not appear when sourceId is not in the url" you refer to not being explicit like this: "http://meusite.com.br/categoryId/10"? if this is the rule RewriteRule ^([^/]*)/categoryId/([^/]*)$ /?sourceId=$1&categoryId=$2 [NC] should solve.

  • hello, I tried that rule again Rewriterule categoryId/([^/])$ /?sourceId=78902565&categoryId=$1 [NC] and it appears like this in the url: http://meusiter.com.br/categoryId/10?sourceId=78902565&categoryId=10, it repeats the whole part after the interrogation ? sourceId=78902565&categoryId=10. And the Rewriterule rule ^([^/])/categoryId/([ /]*)$ /?sourceId=$1&categoryId=$2 [NC] happens the same thing, the url looks like this: http://meusiter.com.br/categoryId/10?sourceId=78902565&categoryId=10,

Browser other questions tagged

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