zblog 301 及伪静态规则设置(含后面的强制斜杠/)
#Nginx
if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break;}if (-f $request_filename/index.php){ rewrite (.*) $1/index.php;}# 自定义规则if (!-f $request_filename){ rewrite ^/(pc|aa|bb|cc)/(\d+).html $scheme://$host/html/$2.html permanent;}# 下边规则只能出现一次并且应该放在最后if (!-f $request_filename){ rewrite (.*) /index.php;}
强制斜线结尾:
# 强制/结尾if (!-f $request_filename) { rewrite ^/([^\.]+[^/])$ $scheme://$host/$1/ permanent;}
理论上可以写在一起:
if (!-f $request_filename){ rewrite ^/.+/(\d+).html $scheme://$host/html/$1.html permanent; rewrite ^/(pc|aa|bb|cc)/(\d+).html $scheme://$host/html/$2.html permanent;}
--------------
Apache .htaccess
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^\.]+[^/])$ /$1/ [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
Nginx
if (!-f $request_filename){ rewrite ^/([^\.]+[^/])$ $scheme://$host/$1$2/ permanent; } if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; }
IIS7、7.5、8+Url Rewrite
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="//" stopProcessing="true"> <match url="^(?!zb_)[^\.]+[^/]$"/> <action type="Redirect" redirectType="Permanent" url="{R:0}/"/> </rule> <rule name="Imported Rule Default+Page" stopProcessing="true"> <match url="^default_([0-9]+)\.html$" ignoreCase="false" /> <action type="Rewrite" url="catalog.asp?page={R:1}" /> </rule> <rule name="Imported Rule Category+Page" stopProcessing="true"> <match url="^category-([0-9]+)_([0-9]+).html$" ignoreCase="false" /> <action type="Rewrite" url="catalog.asp?cate={R:1}&page={R:2}" /> </rule> <rule name="Imported Rule Category" stopProcessing="true"> <match url="^category-([0-9]+).html$" ignoreCase="false" /> <action type="Rewrite" url="catalog.asp?cate={R:1}" /> </rule> <rule name="Imported Rule Author+Page" stopProcessing="true"> <match url="^author-([0-9]+)_([0-9]+).html$" ignoreCase="false" /> <action type="Rewrite" url="catalog.asp?auth={R:1}&page={R:2}" /> </rule> <rule name="Imported Rule Author" stopProcessing="true"> <match url="^author-([0-9]+).html$" ignoreCase="false" /> <action type="Rewrite" url="catalog.asp?auth={R:1}" /> </rule> <rule name="Imported Rule Tags+Page" stopProcessing="true"> <match url="^tags-([0-9]+)_([0-9]+).html$" ignoreCase="false" /> <action type="Rewrite" url="catalog.asp?tags={R:1}&page={R:2}" /> </rule> <rule name="Imported Rule Tags" stopProcessing="true"> <match url="^tags-([0-9]+).html$" ignoreCase="false" /> <action type="Rewrite" url="catalog.asp?tags={R:1}" /> </rule> <rule name="Imported Rule Date+Page" stopProcessing="true"> <match url="^date-([0-9\-]+)_([0-9]+).html$" ignoreCase="false" /> <action type="Rewrite" url="catalog.asp?date={R:1}&page={R:2}" /> </rule> <rule name="Imported Rule Date" stopProcessing="true"> <match url="^date-([0-9\-]+).html$" ignoreCase="false" /> <action type="Rewrite" url="catalog.asp?date={R:1}" /> </rule> <rule name="Imported Rule Article" stopProcessing="true"> <match url="^post/(?!zb_)(.*).html$" ignoreCase="false" /> <action type="Rewrite" url="view.asp?id={R:1}" /> </rule> <rule name="Imported Rule Page" stopProcessing="true"> <match url="^(?!zb_)(.*).html$" ignoreCase="false" /> <action type="Rewrite" url="view.asp?id={R:1}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
来源:
https://bbs.zblogcn.com/thread-94926.html
https://bbs.zblogcn.com/thread-95517.html