本帖最後由 IT_man 於 2016-8-14 21:30 編輯
* x. a* A w+ T1 t @" o3 F2 F7 I: Y2 @2 k* m8 r1 R Z( C
方法有二:/ `* C0 F6 j# {. q( i
〖方法一〗使用.htaccess
% a& p2 K1 Q1 v1 |! `! a& v. E1.開啟網站根目錄之.htaccess(例如/home/test/public_html)
2 J9 s2 r) C( T- RewriteEngine On
[: f% O. u3 g: i' |# h" s" M - RewriteBase /
1 ]; \/ ~& q" w g
! a9 f( |' D) I7 H' i- RewriteCond %{QUERY_STRING} ^(.*)$
1 e# o/ } Y, m# w3 c) h" G - RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topicid=$1&%1; _, G H. i2 u. |
- RewriteCond %{QUERY_STRING} ^(.*)$8 P2 L! S) O" |5 V$ ^
- RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%19 A9 d0 b e% v# |/ B5 v
- RewriteCond %{QUERY_STRING} ^(.*)$
! W8 U0 d7 N% |! T+ E - RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1 c+ F( d) W$ A+ E8 M8 d# }
- RewriteCond %{QUERY_STRING} ^(.*)$
8 {+ O2 `! Z/ h - RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1: e" X0 k1 p2 \ X& f6 Q$ E
- RewriteCond %{QUERY_STRING} ^(.*)$
( Z) M- N) z# | k+ A - RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1
& l, v8 u' d( O$ z8 c; b$ u - RewriteCond %{QUERY_STRING} ^(.*)$
/ [" g6 g8 a2 B |: X( D; c - RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1) V+ [- G) v5 Y" L7 v
- RewriteCond %{QUERY_STRING} ^(.*)$
9 W6 O# I# V; m - RewriteRule ^blog-([0-9]+)-([0-9]+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%16 ]/ C9 P- N# ?# o/ g+ v
- RewriteCond %{QUERY_STRING} ^(.*)$! U2 a5 f) D: m1 E" W
- RewriteRule ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%13 f" M( a3 ]8 T& Y
複製代碼 2.Discuz3.2論壇後台->全局->SEO設置->URL靜態化->勾選所有靜態化 , 立即生效: a: A+ c1 }- d' s% R# T
〖方法二〗使用Apache的rewrite(mod_rewrite)設定
) H1 p: a. ]( s* \ I1.在/etc/httpd/conf/httpd.conf內之<VirtualHost *:80>內的<Directory "/home/domain/public_html">內,或
7 e, Y2 Q4 |- V7 Z5 a在/etc/httpd/conf.d/虛擬主機設定檔如virtual.conf內之<VirtualHost *:80>內的<Directory "/home/domain/public_html">內
! H# G" O- X, L2 {8 Q6 G: w增加以下內容:
+ p; w+ C4 o, K, y# { K/ _1 _) T, d+ t
- RewriteEngine On5 F) s8 e l. N) S0 n# W
- RewriteCond %{QUERY_STRING} ^(.*)$1 J* l; P' W. {; s8 F, [0 ~% Z/ ]
- RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topicid=$1&%10 _& g* _1 |% Y5 |( {" S
- RewriteCond %{QUERY_STRING} ^(.*)$ K9 E) q8 n; A! P- e/ Z% }( U
- RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1
9 q0 f+ G* C/ o) A9 ] - RewriteCond %{QUERY_STRING} ^(.*)$
0 v% g0 ?6 m/ {$ o$ `0 H - RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1' |+ H* y: {% o2 C z, P) R
- RewriteCond %{QUERY_STRING} ^(.*)$" A: u! T9 b; d- X/ M( e
- RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%16 Q3 l" o, ?0 K# I; f& [
- RewriteCond %{QUERY_STRING} ^(.*)$
6 H) I& h1 i- V - RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1
" y' `1 p B: T2 k m8 N - RewriteCond %{QUERY_STRING} ^(.*)$
9 Q$ ~0 Z) N; R0 c# p/ T; k - RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1' D2 J3 s8 x& F! E2 B( P. c
- RewriteCond %{QUERY_STRING} ^(.*)$/ }3 @( p1 |5 ]1 F! [
- RewriteRule ^blog-([0-9]+)-([0-9]+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1
# V7 ~4 C3 }& L - RewriteCond %{QUERY_STRING} ^(.*)$: ~" i+ K, b( `: \
- RewriteRule ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%14 u: R3 n/ S* l1 n- b
複製代碼 2.在/etc/httpd/conf/httpd.conf內需有0 z$ R9 G3 I- y! u1 I/ f
LoadModule rewrite_module modules/mod_rewrite.so 這一行 t* f+ \1 t" t$ R/ ^
然後重啟 httpd ==> service httpd restart
& ?+ M* L" Q( y9 [" q
) k! ?! y1 j6 f9 Y5 o% m$ }
- |" V/ \3 p( S+ P0 @* m |
|