URL 重写 web.config 中的 php 个文件

URL Rewriting for php files in web.config

我这里有一些问题,我已经检查了这里另一个 post 的所有答案,但我遇到了 500 错误,或者没有任何反应。

问题是:

假设我有一个类似这样的网站:flan.com

所以,我有一个动态的 URL 比如:

flan.com/index.php?page=25flan.com/news.php?news=aqweqwr546

请注意,此值 "aqweqwr546" 是动态的,可以是数字或字母或两者兼而有之。

我需要这样的东西:

第一个:flan.com/page/a title shown here

第二个:flan.com/news/a title shown here

或类似这样的用户友好的东西 URL!

请提前帮助me.Thanks

在您网站的根目录中创建或编辑 .htaccess 文件,并将其放入:

RewriteEngine On

RewriteRule /(.*)/$ news.php?news=

这会给你一个看起来像这样的 url:

flan.com/aqweqwr546/

或者这样:

RewriteRule /(.*)/(.*)/$ .php?news=

会给你这个:

flan.com/news/aqweqwr546/

像这样重写您的网址...

RewriteEngine On
#For home page. i.e. index.php
RewriteRule ^page/([a-zA-Z0-9]+)$ index.php?page= [L]

#For news page i.e news.php
RewriteRule ^news/([a-zA-Z0-9]+)$ news.php?news= [L]

web.config这样..

<rewrite>
  <rules>
    <rule name="Rewrite to index.php">
      <match url="^page/([a-zA-Z0-9]+)$"/>
      <action type="Rewrite" url="index.php?page={R:1}/>
    </rule>
    <rule name="Rewrite to news.php">
      <match url="^news/([a-zA-Z0-9]+)$"/>
      <action type="Rewrite" url="news.php?news={R:1}/>
    </rule>
  </rules>
</rewrite>