mod_rewrite的 - 创造清洁的网址 [英] Mod_rewrite - Create Clean URLs

查看:135
本文介绍了mod_rewrite的 - 创造清洁的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想创造清洁的URL访问我们的网站。我已经搜索了怎么会这样做,我已经找到了code片段,但它不符合我的要求。在这里,我要解释一下,我们基本上要。

We would like to create clean URLs to our website. I have searched that how could this be done and I have found a code snippet, however it doesn't fulfil my requirements. Here I'm going to explain what we basically want.

这是基本的网站网址: http://www.test.com

This is the basic website's URL: http://www.test.com

我们有一个页面菜单,其中列出了用户可以看到特定页面。它看起来像以下内容: http://www.test.com/pages.php

We have a "pages" menu, which lists specific pages which users can see. It looks like the following: http://www.test.com/pages.php

我们基本上要当有人访问该 /pages.php 应重定向到的 /网页(或全网址: test.com/pages )或不定向,只是显示没有找到页面。

We basically want that when someone visits this /pages.php it should redirect them to /pages (or with full URL: test.com/pages) or not redirect, just show a page not found.

还应该有这些可能的配置工作:

It should also work with any of these possible configurations:


  • /页

  • /页/

  • /page.php

我已经看过Stackowerflow的制度,它是工作,我们实际上希望的方式。所以每次我在看之一:

I have looked at Stackowerflow's system, and it is working the way we would actually want it. So every time I'm looking at either:


  • stackoverflow.com/questions

  • stackoverflow.com/questions /

  • stackoverflow.com/questions.php - 显示未找到页面的网站

这基本上是我需要的。我已经试过这code,但它并不满足我的需求完全工作:

This is basically what I need. I have tried this code, but it does not work fully for my needs:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]

我会很高兴,如果任何人都可以写一个明确的解释如何才能实现这一目标。此外,如果你觉得这篇文章复制,请联系我确切的职位,因为我一直在寻找这个确切问题,但我没有找到任何答案吧。

I'd be pleased if anyone could write a clear explanation how can this be achieved. Also if you find this post duplicated, please link me the EXACT post, because I have been searching for this exact question, but I didn't find any answers to it.

感谢

推荐答案

OK,写这样的事情。

OK, write something like this.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName deli.localhost

    DocumentRoot /var/www/deli/
    <Directory /var/www/deli/>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all

                RewriteEngine on

                ## Externally redirect clients directly requesting .(php|aspx|html|htm|pl|cgi|asp)+ page 
                ## URIs to extensionless URIs
                ## If client request header contains php,aspx,html or htm file extension, redirect
                ## It avoids an infinite loop since "THE_REQUEST" is what the UA asks for, not what the 
                ## server translates it to on the second pass.
                ## THE_REQUEST syntax is something like: GET /page.html HTTP/1.0
                RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.(php|aspx|html|htm|pl|cgi|asp)+(/.*)?\ HTTP [NC]
                RewriteRule ^([^.]+)\.(php|aspx|html|htm|pl|cgi|asp)+(/.*)?$ http://xyz.com/$1$3 [NC,R=301,L]


                FileETag none





                ErrorDocument 401 /401.php
                ErrorDocument 403 /403.php
                ErrorDocument 404 /404.php
                ErrorDocument 500 /500.php
                ErrorDocument 503 /503.php
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined
</VirtualHost>

这篇关于mod_rewrite的 - 创造清洁的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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