How to solve the case when users switch to index.php

In Zend using MVC, if the user explicitly looks at http: //base/url/index.php instead of http: // base / url , the system considers that the real base url is http: //base/url/index.php/ and matches to which all the URLs in the system are calculated.

So, if I have a XXX controller and a YYY action, the Link will be
http: //base/url/index.php/XXX/YYY , which, of course, is wrong.

I am currently solving this by adding a line to index.php:

$_SERVER["REQUEST_URI"]=str_replace('index.php','',$_SERVER["REQUEST_URI"]);

I am wondering if there is a built-in way in ZF to solve this problem.

+3
source share
6 answers

You can do this with ZF using Zend_Controller_Router_Route_Static(phew!), For example:

Read the man page above, there are some good examples you can find.

$route = new Zend_Controller_Router_Route_Static(
    'index.php',
    array('controller' => 'index', 'action' => 'index')
);
$router->addRoute('index', $route);

I can’t say that I completely disagree with your approach. However, others may point to 5,000 or so deficiencies. Good luck with that.

+5
source

Well, it really depends on how you want to solve it. As you know, Zend Frameworks is based on the front controller template, where every request that does not explicitly refer to a file in the / public directory is redirected to index.php. Thus, you can basically solve this in several ways:

  • .htaccess( ), :
    • RewriteRule (. * index.php)/error/forbidden? req = $1// .
    • RewriteRule index.php/index//
  • , karim79.
+2

mod_rewrite. - :

RewriteRule ^index.php/(.*)$ /$1 [r=301,L]
+2

, .

, .

.htaccess, , , .

mod_rewrite

0

, Zend Framework. index.php. . , http://base/url/

http://base/url/, URI /url, .htaccess index.php, IS base/url. 'index.php' . .

URL- ..., url() . :

// in some view script
<a href="<?php
  echo $this->url( array('controller'=>'targetController','action'=>'targetAction') );
         ?>" >click</a>

. Zend URL-.

0

As I look at this, if I have a site based on PHP and the user goes to http: //site/index.aspx , then I would send a 404 message.

Although index.php exists in theory, it is not a valid URL in my application, so I will also send 404 in this case.

0
source

Source: https://habr.com/ru/post/1708946/


All Articles