【问题标题】:Allow URLs with Dashes on azure websites在 azure 网站上允许带有破折号的 URL
【发布时间】:2015-09-03 03:31:07
【问题描述】:

我正在尝试为下载页面创建一个 SEO 友好的链接 使用托管在 Azure 网站上的 codeigniter,现在可以正常工作了:

www.example.com/downloads/viewfile/34

现在当我生成此链接时:

www.example.com/downloads/viewfile/my-nice-file-name-34

Url 重写在 WAMP 服务器上本地工作得很好,但是当部署到远程(Azure Webites IIS ?)时,它会给出错误:

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

我认为原因是:IIS 上不允许使用破折号,但有办法解决吗?

【问题讨论】:

  • IIS 上的 PHP/Codeigniter - 呸。
  • 如何用破折号生成第二个链接?使用 .htaccess 还是使用 routes.php ?
  • 只使用辅助函数 url_title()

标签: codeigniter url iis url-rewriting azure-web-app-service


【解决方案1】:

在你的 routes.php 文件中

寻找

$route['translate_uri_dashes'] = FALSE;

替换为

$route['translate_uri_dashes'] = TRUE;

您可能还需要查看

URI 路由 Codeigniter 3

http://www.codeigniter.com/user_guide/general/routing.html

Codeigniter 2 URI 路由

http://www.codeigniter.com/userguide2/general/routing.html

【讨论】:

    【解决方案2】:

    毕竟,我发现不是破折号导致问题,而是 url 本身中的单词

    就像昨天我有www.example.com/downloads/viewfile/example-file-34 出于某种原因,在 url 段中包含您的域名会导致该错误出现,所以我只是在生成 Url 段之前将“mydomain”替换为空

    $fileName = str_replace('mydomain','',$fileName);
    return url_title($fileName.$fileId);
    

    现在上面的同一个链接是www.example.com/downloads/viewfile/file-34,它工作正常。

    我还注意到在使用诸如 ajax、json 之类的词时会出现相同的行为。

    我希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多