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

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

问题描述

我很久以来一直在想,人们如何设法让他们的网址在没有文件扩展名的情况下工作,比如'.html'或'.apsx'。

请看这个网站,例如:

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

他们是如何完成这项工作的?我能想到的唯一方法是为每个页面创建一个新目录,并在每个目录中都有一个索引页面,但这对于较大的网站来说是一个巨大的麻烦。有没有其他的办法?



Thankyou

解决方案

通常的方法是:使用索引页(即只需创建一个目录并将 index.html code> file)。

  • 使用重写引擎(例如Apache的 mod_rewrite )将URL映射到不同的文件上(这是PHP-land中的常用方法)。
  • 使用前端控制器脚本为您处理URL(这是MVC框架的常用方法)。


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

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

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

    对于使用WSGI的脚本(Python)或FastCGI(跨语言,这个特定的例子是从我写的Perl应用程序中分离出来的)。



    URL格式将由脚本处理本身,不同的框架采取不同的方法来解决这个问题。



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

    Dancer拥有自己的路径处理程序语法



    Web :: Simple使用子程序原型

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

    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.

    Look at this website for example:

    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?

    Thankyou

    解决方案

    The three most common ways are to:

    • 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).

    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
    

    or

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

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

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

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

    Dancer has its own route handler syntax.

    Web::Simple uses subroutine prototypes.

    Django uses a separate file containing a list of patterns.

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

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