的.htaccess动态静态URL

编程入门 行业动态 更新时间:2024-10-22 09:43:20
本文介绍了的.htaccess动态静态URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图让我的动态网址到静态URL的。 这是我现在有一个典型的网址: www.somedomain/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: www.somedomain/design/index.php?p=about

我想它是: www.somedomain/about

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

So far, I've gotten it to look like this: www.somedomain/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]

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

How would I modify it so it would look like this: www.somedomain/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

本文发布于:2023-11-01 12:35:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549352.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   动态   htaccess   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!