.htaccess Htaccess别名重定向假多语言url

.htaccess Htaccess别名重定向假多语言url,.htaccess,mod-rewrite,url-rewriting,.htaccess,Mod Rewrite,Url Rewriting,我有一个域名www.domain.com和这种url www.domain.com/my意大利语page.html(已被其他htaccess规则改写) 我想创建一个假的多语言url,比如 www.domain.com/my english page.html 用户将在地址栏中看到重写器urlwww.domain.com/my english page.html,但我要显示的内容是原始的www.domain.com/my意大利语page.html 我在共享服务器上,因此无法使用apache vho

我有一个域名www.domain.com和这种url

www.domain.com/my意大利语page.html(已被其他htaccess规则改写)

我想创建一个假的多语言url,比如

www.domain.com/my english page.html

用户将在地址栏中看到重写器urlwww.domain.com/my english page.html,但我要显示的内容是原始的www.domain.com/my意大利语page.html

我在共享服务器上,因此无法使用apache vhost规则,因此必须通过htaccess找到解决方案

有人能帮我找到正确的方法吗


谢谢

那么您想要指向意大利内容的英文URL吗?希望生成这些重写规则的php脚本能够进行翻译。但你应该为每一页都这样做:

RewriteRule ^/?english-page.html$ /italian-page.html [L]

对于你的每一页。

那么你想要指向意大利内容的英文URL?希望生成这些重写规则的php脚本能够进行翻译。但你应该为每一页都这样做:

RewriteRule ^/?english-page.html$ /italian-page.html [L]

对于每个页面。

通常,您希望在web服务器中执行的代码尽可能小,因此为每个页面设置重写规则通常不是一个好主意。我建议在启用SEO URL时,以大多数CMS的方式实现这一点:

  • 将任何url(
    mydomain/anytext.html
    [实际上也不应该使用.html扩展名])重写为脚本(例如
    mydomain.tld/translate.php

  • 使用
    $\u服务器['PATH\u INFO']
    (应包含
    anytext.html
    )的内容显示正确的页面

  • 若页面不存在,则设置正确的HTTP响应代码:(请参阅本答案末尾,了解5.4以下php5上的函数:)

htaccess(实际上最初是“被盗”的,并从typo3设置中进行了严重修改)

非常基本的伪代码,如(未测试,可能存在语法错误)示例:

<?php
// using a database? you have to escape the string
$db = setup_db();
$page = db->escape_string(basename($_SERVER['PATH_INFO']));
$page = my_translate_query($page);

// no database? do something like this.
$trans = array( 'english' => 'italian', 'italian' => 'italian' );
$page = 'default-name-or-empty-string';
if(isset($_SERVER['PATH_INFO'])) {
   if(isset($trans[basename($_SERVER['PATH_INFO'])])) {
      $page = $trans[$trans[basename($_SERVER['PATH_INFO'])]];
   }
   else {
      http_response_code(404);
      exit();
   }
}

// need to redirect to another script? use this (causes reload in browser)
header("Location: otherscript.php/$page");
// you could also include it (no reload), try something like this
$_SERVER['PATH_INFO'] = '/'.$page;
// you *may* have to modify other variables like $_SERVER['PHP_SELF']
// to point to the other script
include('otherscript.php');
?>


我在您的回答中看到您还有另一个脚本-
dispatcher.php
,您似乎不愿意修改它。我相应地修改了我的响应,但请记住,到目前为止,最简单的方法是修改现有脚本以处理任何英文路径本身。

通常,您希望在web服务器中执行的代码尽可能小,因此为每个页面设置重写规则通常不是一个好主意。我建议在启用SEO URL时,以大多数CMS的方式实现这一点:

  • 将任何url(
    mydomain/anytext.html
    [实际上也不应该使用.html扩展名])重写为脚本(例如
    mydomain.tld/translate.php

  • 使用
    $\u服务器['PATH\u INFO']
    (应包含
    anytext.html
    )的内容显示正确的页面

  • 若页面不存在,则设置正确的HTTP响应代码:(请参阅本答案末尾,了解5.4以下php5上的函数:)

htaccess(实际上最初是“被盗”的,并从typo3设置中进行了严重修改)

非常基本的伪代码,如(未测试,可能存在语法错误)示例:

<?php
// using a database? you have to escape the string
$db = setup_db();
$page = db->escape_string(basename($_SERVER['PATH_INFO']));
$page = my_translate_query($page);

// no database? do something like this.
$trans = array( 'english' => 'italian', 'italian' => 'italian' );
$page = 'default-name-or-empty-string';
if(isset($_SERVER['PATH_INFO'])) {
   if(isset($trans[basename($_SERVER['PATH_INFO'])])) {
      $page = $trans[$trans[basename($_SERVER['PATH_INFO'])]];
   }
   else {
      http_response_code(404);
      exit();
   }
}

// need to redirect to another script? use this (causes reload in browser)
header("Location: otherscript.php/$page");
// you could also include it (no reload), try something like this
$_SERVER['PATH_INFO'] = '/'.$page;
// you *may* have to modify other variables like $_SERVER['PHP_SELF']
// to point to the other script
include('otherscript.php');
?>


我在您的回答中看到您还有另一个脚本-
dispatcher.php
,您似乎不愿意修改它。我相应地修改了我的回答,但请记住,到目前为止,最简单的方法是修改现有的脚本,以处理任何英文路径本身。

您是否希望像总是将“la mia vacanza recente”(不要打我,我使用谷歌翻译)这样的静态重写为“我最近的假期”或者你想对多篇文章进行动态重写?更准确地说:这是一个电子商务。因此,我必须重新创建一个重写foreach产品url。例如,我在意大利语www.mydomain.com/burro.html中创建了一个php脚本,将一个规则写入htaccess foreach产品,以获得类似假英语www.mydomain.com/butter.html的内容。因此,如果用户将访问www.mydomain.com/butter.html,我希望显示该url地址栏上的是/butter.html,但内容来自原始的burro.html。显然,我会将这两个干净的url保存在数据库中,然后我会调用php脚本将规则写入.htaccess。您是否希望像总是将“la mia vacanza recente”(我使用google translate时不要点击我)这样的静态重写为“我最近的假期”或者你想对多篇文章进行动态重写?更准确地说:这是一个电子商务。因此,我必须重新创建一个重写foreach产品url。例如,我在意大利语www.mydomain.com/burro.html中创建了一个php脚本,将一个规则写入htaccess foreach产品,以获得类似假英语www.mydomain.com/butter.html的内容。因此,如果用户将访问www.mydomain.com/butter.html,我希望显示该url地址栏上的是/butter.html,但内容来自原始的burro.html。显然,我会将两个干净的url保存在数据库中,然后调用php脚本将规则写入。htaccess.Yes,php脚本会翻译除url以外的所有内容。我认为是其他一些规则导致了这个问题。我的htaccess
Options+FollowSymLinks-MultiViews-Indexes RewriteEngine在RewriteBase/acquista/RewriteCond%{REQUEST_URI}^/获取/(付款|管理|提供商|合作伙伴)/RewriteCond%{REQUEST\u FILENAME}!\。(gif | jpe?g | png | js | css | swf | php | ico)$RewriteCond%{REQUEST_FILENAME}-f RewriteCond%{REQUEST_FILENAME}-已重写COND%{REQUEST_FILENAME}-l RewriteRule^/?butter of cacao biologic.html$/Burro-di-cacao-Biologio.html RewriteRule^(.*)$dispatcher.php[l]
@user1625783您可能希望将该规则放在
RewriteBase/acquista/
之后,或者更好,放在文档根目录下的htaccess文件中,因为它是
www.domain.com/my english page.html
而不是
www.domain.com/acquista/my english page.html
是的,php脚本