如何在没有任何文件扩展名的情况下获取用户友好的 URL? [英] How to get user friendly URLs without any file extensions?

查看:29
本文介绍了如何在没有任何文件扩展名的情况下获取用户友好的 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很长一段时间以来,我一直想知道人们如何在没有文件扩展名(例如.html"或.apsx")结尾的情况下设法让他们的 URL 正常工作.

I've been wondering for a long time how people manage to get their URLs to work without file extentions such as '.html' or '.apsx' on the end.

以这个网站为例:

http://www.axongarside.com/Communication
http://www.axongarside.com/Communication/Compleat
http://www.axongarside.com/Brand
http://www.axongarside.com/Brand/K3-Group

他们是如何做到这一点的?我能想到的唯一方法是为每个页面创建一个新目录并在每个目录中有一个索引页面,但这对于较大的网站来说将是一个巨大的麻烦.还有其他办法吗?

How have they accomplished this? The only method I can think of would be to create a new directory for each page and have an index page in each directory but this would be a huge hassle for a larger website. Is there any other way?

谢谢

推荐答案

最常见的三种方式是:

  • 使用索引页面(即只需创建一个目录并在其中放置一个 index.html 文件).
  • 使用重写引擎(例如 Apache 的 mod_rewrite)来映射 URL到不同的文件(这是 PHP 领域的常用方法).
  • 使用前端控制器脚本为您处理 URL(这是 MVC 框架的常用方法).
  • Use index pages (i.e. just create a directory and put an index.html file in it).
  • Use a rewrite engine (such as Apache's mod_rewrite) to map the URLs onto different files (this is a common approach in PHP-land).
  • Use a front controller script which processes the URLs for you (this is the usual approach for MVC frameworks).

后一种方法会在 Apache 服务器配置中使用类似的东西:

The latter approach would use something like this in an Apache server configuration:

WSGIDaemonProcess example processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup example
WSGIScriptAlias / /hosts/example.com/application/wsgi.py

SetHandler fcgid-script
Alias / /hosts/example/application.fcgi/

对于分别使用 WSGI (Python) 或 FastCGI(跨语言,该特定示例来自我正在编写的 Perl 应用程序)的脚本.

For scripts using WSGI (Python) or FastCGI (Cross-language, that particular example was cribbed from a Perl application I'm writing) respectively.

URL 格式将由脚本本身处理,不同的框架对问题采取不同的方法.

The URL format would be handled by the script itself, and different frameworks take different approaches to the problem.

在 Catalyst 中,这是通过 为子程序名称提供属性.

In Catalyst, this is done by providing attributes to subroutine names.

Dancer 有自己的路由处理程序语法.

Dancer has its own route handler syntax.

Web::Simple 使用 子程序原型.

Web::Simple uses subroutine prototypes.

Django 使用一个包含模式列表的单独文件.

这篇关于如何在没有任何文件扩展名的情况下获取用户友好的 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆