user1775888
user1775888

Reputation: 3313

url rewrite and google robots txt

I use php slim framework, with url rewrite here is my host real file structure:
like most framework all rewrite to index.php

/.htaccess
/assets
/index.php
/phpinfo.php
/robots.txt
/usr
    /controller
    /model
    ...

and here is my router

$app->get('/backstage', $authenticate(), function () use ($uri, $app) {...});
$app->get('/api', $authenticate(), function () use ($uri, $app) {...});

$app->get('/', function () use ($uri, $app) {...});
$app->get('/article', function () use ($uri, $app) {...});

How to disable /backstage, /api in my route, and real file path /phpin.php, /usr,
And accept /, /article in router?

I'm confusing should I fill router path or real file path? because real file path there is not exist /article


and this is I tried

User-agent: *
Disallow: /backstage/
Disallow: /phpinfo.php

Upvotes: 0

Views: 389

Answers (1)

Trick
Trick

Reputation: 646

First (assuming you use apache), you need to make sure your .htaccess file correctly points requests to your router file.

--- begin .htaccess snippet ---

<IfModule mod_rewrite.c>
    RewriteEngine On    
    ## direct all requests to Slim router
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ slim-router.php [QSA,L]
</IfModule>

--- end .htaccess snippet ---

I may not be understanding your question properly, but to disable a route, simply comment out the line in slim-router.php that adds the route.

Adding entries to robots.txt will not prevent browsers from reaching a URI, it only exists to ask search engine bots (i.e., GoogleBot) to not index that particular URI. See robotstxt.org and the robots.txt entry on Wikipedia.

To direct a route to an existing file, you can use the \Slim\View class (see the \Slim\View documentation). This example expects a file named templates/article.php to exist, which is the file that will output the content for the /article route. Using the \Slim\View class, you can also send data to the template file, which I have demonstrated below as well. This is only a basic example, see the documentation for more complex usage.

//--- begin slim-router.php ---

    $app = new \Slim\Slim();
    $defview = new \Slim\View();
    $defview->setTemplatesDirectory(realpath(__DIR__).'/templates');

    $app->get(
        '/article',
        function () use ($app) {
          global $defview;
          //show the contents of 'templates/article.php', passing optional data to the template file:
          $app->view($defview)->display(
              'article.php', 
              array(
                 'data_one'=>'one',
                 'data_two'=>2,
                 'three'=>'3',
              )
          );
        }
    );        

//--- end slim-router.php ---

Upvotes: 1

Related Questions