繁体   English   中英

.htaccess动态网址的重写规则

[英].htaccess rewrite rules for Dynamic URL

我想使用来自以下位置的.htaccess文件为动态网站创建url重写规则:

http://localhost/pincode/pinpo.php?po=Ameda

至:

http://localhost/pincode/postoffice/Ameda.php

如何改变呢?

在您的pincode/.htaccess文件中使用它

   RewriteEngine on
  RewriteBase /pincode/
RewriteRule ^postoffice/(.*)\.php$ /pincode/pinpo.php?po=$1 [QSA,NC,L]

从服务器的角度来看,该过程是相反的,它将伪造的静态url重写为可检索动态内容的动态url。

您网站(request_uri)中的网址应为

HTTP://localhost/pincode/postoffice/Ameda.php

而且,您在webroot中的.htaccess文件应包含:

    RewriteEngine on
    RewriteBase /
    RewriteRule ^pincode/postoffice/(.*)\.php$ /pincode/pinpo.php?po=$1 [L]

如果您想将动态重写为静态,则仍然需要两个重写规则才能通过这种方式进行动态数据检索:

    RewriteEngine on
    RewriteBase /                                
    #static to dynamic, with nol arg to prevent infinite looping    
    RewriteRule ^pincode/postoffice/([a-z0-9]+).php$ pincode/pinpo.php?nol&po=$1 [L]
    #dynamic to static:
    RewriteCond %{QUERY_STRING} ^po=([a-zA-Z0-9]+)$
    RewriteRule ^/pincode/pinpo.php$ pincode/postoffice/%1.php [L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM