网站内有2个不同的网址

时间:2018-07-13 18:58:46

标签: php .htaccess

当我用htaccess重写网址时,我有两个不同的网址。

正常网址: http://localhost/clicshopping_test/boutique/index.php/Products/Description/products_id,1

htaccess:  http://localhost/clicshopping_test/boutique/Products/Description/products_id,1

index.php/已删除。

问题是网站内的链接未重写。

我尝试添加:

$link = str_replace('index.php/', '',$link);

此代码中的链接与url具有相同的链接,这是行不通的。

您对此有想法吗?

if ($search_engine_safe === true && defined('SEARCH_ENGINE_FRIENDLY_URLS') && SEARCH_ENGINE_FRIENDLY_URLS == 'true' && SEFU::start() && static::getSite() != 'ClicShoppingAdmin') {
    $link = str_replace(['?', '&', '='], ['/', '/', ','], $link);

    $link = str_replace('index.php/', '',$link);
  }

tk。

有关OSCOM :: link的功能:

   public static function link($page, $parameters = null, $add_session_id = true, $search_engine_safe = true)  {

  $page = HTML::sanitize($page);

  $site = $req_site = static::$site;

  if ((strpos($page, '/') !== false) && (preg_match('/^([A-Z][A-Za-z0-9-_]*)\/(.*)$/', $page, $matches) === 1) && CLICSHOPPING::siteExists($matches[1], false)) {
      $req_site = $matches[1];
      $page = $matches[2];
  }

  if (!is_bool($add_session_id)) {
    $add_session_id = true;
  }

  if (!is_bool($search_engine_safe)) {
    $search_engine_safe = true;
  }

  if (($add_session_id === true) && ($site !== $req_site)) {
    $add_session_id = false;
  }

  $link = static::getConfig('http_server', $req_site) . static::getConfig('http_path', $req_site) . $page;

  if (!empty($parameters)) {
    $p = HTML::sanitize($parameters);

    $p = str_replace([
                      "\\", // apps
                      '{', // product attributes
                      '}' // product attributes
                      ], [
                        '%5C',
                        '%7B',
                        '%7D'
                      ], $p);

    $link .= '?' . $p;
    $separator = '&';
  } else {
    $separator = '?';
  }

  while((substr($link, -1) == '&') || (substr($link, -1) == '?')) {
    $link = substr($link, 0, -1);
  }

///当从不同的HTTP和HTTPS服务器移动或定义了SID时,添加会话ID       如果(($ add_session_id === true)&& Registry :: exists('Session')){         $ CLICSHOPPING_Session =注册表:: get('Session');

    if ($CLICSHOPPING_Session->hasStarted() && ($CLICSHOPPING_Session->isForceCookies() === false)) {
      if ((strlen(SID) > 0) || (((HTTP::getRequestType() == 'NONSSL') && (parse_url(static::getConfig('http_server', $req_site), PHP_URL_SCHEME) == 'https')) || ((HTTP::getRequestType() == 'SSL') && (parse_url(static::getConfig('http_server', $req_site), PHP_URL_SCHEME) == 'http')))) {
        $link .= $separator . HTML::sanitize(session_name() . '=' . session_id());
      }
    }
  }

  while(strpos($link, '&&') !== false) {
    $link = str_replace('&&', '&', $link);
  }


  if ($search_engine_safe === true && defined('SEARCH_ENGINE_FRIENDLY_URLS') && SEARCH_ENGINE_FRIENDLY_URLS == 'true' && SEFU::start() && static::getSite() != 'ClicShoppingAdmin') {
    $link = str_replace(['?', '&', '='], ['/', '/', ','], $link);

// $ link = str_replace('index.php /','',$ link);       }

  return $link;
}

HTML :: link的功能

 public static function link($url, $element, $parameters = null) {
      return '<a href="' . $url . '"' . (!empty($parameters) ? ' ' . $parameters : '') . '>' . $element . '</a>';
}

通话:

  $products_image = HTML::link(OSCOM::link('index.php', 'Products&Description&products_id=' . $products_id), HTML::image($CLICSHOPPING_Template->getDirectoryTemplateImages() . $CLICSHOPPING_ProductsCommon->getProductsImage($products_id), HTML::outputProtected($products_name_image), (int)SMALL_IMAGE_WIDTH, (int)SMALL_IMAGE_HEIGHT));

我的htaccess

Options -Indexes
Options +FollowSymlinks

#note for apache2 must be activated becarefull on apache 2.4
#AllowOverride All
#AcceptPathInfo on


#### Your config to change ###############
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On


#to change in function your website
RewriteBase /test/boutique/

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

#to change in function your website
RewriteRule . /test/boutique/index.php [L]

#to change in function your website
#uncomment to have clear url
RewriteCond %{THE_REQUEST} /test/boutique/index\.php/(\S*)\s [NC]

    RewriteRule ^ %1 [L,R=301,NE]
</IfModule>

0 个答案:

没有答案