htaccess动态静态URL

htaccess动态静态URL

本文介绍了的.htaccess动态静态URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的动态网址到静态URL的。这是我现在有一个典型的网址: http://www.somedomain.com/design/index.php?p=about

I'm trying to make my dynamic URL's into static looking URL's.This is a typical URL that I now have:http://www.somedomain.com/design/index.php?p=about

我想它是: http://www.somedomain.com/about

到目前为止,我已经得到它看起来像这样: http://www.somedomain.com/design/about.html

So far, I've gotten it to look like this: http://www.somedomain.com/design/about.html

这是我使用的重写规则:重写规则^([AZ] +)HTML $的index.php P = $ 1 [L]

This is the Rewriterule I'm using: RewriteRule ^([a-z]+).html$ index.php?p=$1 [L]

我将如何修改它,所以它看起来是这样的: http://www.somedomain.com/about

How would I modify it so it would look like this: http://www.somedomain.com/about?

感谢任何/所有的帮助!非常AP preciated!

Thanks for any/all help!!!Very much appreciated!

推荐答案

里克,你是在正确的轨道。你需要阅读Apache重写文件。为了您的文档根目录/的.htaccess 与启动:

Rick, you're on the right track. You need to read the Apache rewrite documentation. For your docroot/.htaccess start it with:

 RewriteEngine On
 RewriteBase   /

你的规则那么通用版本:

Then generalised version of your rule:

 Rewrite Rule ^(\w+)$     index.php?p=$1 [L]

这将改写这对于一个字串到的index.php 的任何请求。你需要知道,重写引擎重新扫描,如果匹配已发生,所以你需要确保你没有创建一个循环的.htaccess 文件。在这种情况下,替换字符串有一个,在它和模式没有,因此这不会发生,但对于更复杂的情况下,您可能需要警卫与一个或多个的RewriteCond 语句的规则。此外,阅读Apache文档。

This will rewrite any requests which are for a word string to index.php. You need to be aware that the rewrite engine rescans the .htaccess file if a match has occured so you need to make sure that you don't create a loop. In this case the replacement string has a "." in it and the pattern doesn't, so this won't occur, but for more complex cases you may need to 'guard' the rules with one or more RewriteCond statements. Again, read the Apache documentation.

这篇关于的.htaccess动态静态URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 05:57