本帖最後由 IT_man 於 2016-8-14 21:30 編輯 0 p( P4 u2 Y* J- p
; f2 u# |) _5 v0 {& H4 A* I
方法有二:
0 I" _( t5 b. L: p〖方法一〗使用.htaccess
: Z: o$ L: b' K1 i" V. x$ A+ a1.開啟網站根目錄之.htaccess(例如/home/test/public_html)$ v6 r# |& n0 l- O9 b
- RewriteEngine On- _: d4 v/ Q& {0 t
- RewriteBase /
8 d) i' z- A; L% Y, d - & J+ R# r8 }: L6 Q# M
- RewriteCond %{QUERY_STRING} ^(.*)$
- ^& g; Y7 B% D. N+ ^ - RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topicid=$1&%15 z5 k5 [2 j: l$ Z, T% S
- RewriteCond %{QUERY_STRING} ^(.*)$
; X9 K7 f( W# m- k/ T- ^# b0 N - RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1
) R" Y* q! f' ^) k' ] - RewriteCond %{QUERY_STRING} ^(.*)$
" _+ v# u4 Z! X! ^7 F& A" j9 ] - RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1, e" x# o4 p/ V6 G
- RewriteCond %{QUERY_STRING} ^(.*)$
# V) ?* h* I X! D7 s - RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1( Y5 N0 _6 l8 V9 t6 C
- RewriteCond %{QUERY_STRING} ^(.*)$
+ g# Y0 e0 z7 ~ A3 h9 w - RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%18 u' F7 D) R S' F0 L: g* T
- RewriteCond %{QUERY_STRING} ^(.*)$0 ?: r- {2 M: _( ^6 f
- RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1( O p3 v8 n& ?; d
- RewriteCond %{QUERY_STRING} ^(.*)$. ]2 ^2 f/ P: Z+ p7 P& [
- RewriteRule ^blog-([0-9]+)-([0-9]+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1
; r: l, ~& t* P7 Q - RewriteCond %{QUERY_STRING} ^(.*)$* h* S S* A2 B6 i6 C5 d
- RewriteRule ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%1
8 h7 t! W$ R3 R
複製代碼 2.Discuz3.2論壇後台->全局->SEO設置->URL靜態化->勾選所有靜態化 , 立即生效( V) I" f) a5 ?
〖方法二〗使用Apache的rewrite(mod_rewrite)設定2 c0 R: X6 |/ v8 J
1.在/etc/httpd/conf/httpd.conf內之<VirtualHost *:80>內的<Directory "/home/domain/public_html">內,或7 r1 r8 O% Q1 Y; r% C- @! |
在/etc/httpd/conf.d/虛擬主機設定檔如virtual.conf內之<VirtualHost *:80>內的<Directory "/home/domain/public_html">內
. a7 I: w0 y8 U增加以下內容:5 t/ S+ S+ q8 P3 t) a- N1 G- z
( w, G' Z# s, Q* G- RewriteEngine On
3 {& ^# ^7 o, n( W" E - RewriteCond %{QUERY_STRING} ^(.*)$
' z8 D$ ^+ }* Y - RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topicid=$1&%1
' k' i- b, s% W% l% B$ J, k! E - RewriteCond %{QUERY_STRING} ^(.*)$
' H/ J. d: {" H9 x/ o - RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1
# ^5 O0 q2 N0 f- |* k+ k, S8 K! k v - RewriteCond %{QUERY_STRING} ^(.*)$
. @- A6 g1 k [5 O6 }3 z: E - RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1
( O7 J) b, D) f2 K W - RewriteCond %{QUERY_STRING} ^(.*)$
% Q# Q C" G! e! M+ N5 r8 | - RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%10 u8 r, W! v" b. ]' c
- RewriteCond %{QUERY_STRING} ^(.*)$
6 l9 _% @; X8 t - RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%18 O( |# H# ]/ e) C3 X+ F
- RewriteCond %{QUERY_STRING} ^(.*)$
! l" V- z9 r& f5 t" k# ] - RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1
* E8 P5 }/ z" s7 J. g - RewriteCond %{QUERY_STRING} ^(.*)$, Z' \8 o; N& _# S: H/ X
- RewriteRule ^blog-([0-9]+)-([0-9]+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1
% F+ I# j& D7 ] a x1 s0 l - RewriteCond %{QUERY_STRING} ^(.*)$
. ~: s, P: P" E; y5 D: ^7 A - RewriteRule ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%1
: P4 q+ N7 X8 S' z1 D
複製代碼 2.在/etc/httpd/conf/httpd.conf內需有) i2 y5 l6 z% u: z+ X# C
LoadModule rewrite_module modules/mod_rewrite.so 這一行0 e9 G& r3 H, u5 D1 x: C" y) `
然後重啟 httpd ==> service httpd restart
6 L# Z2 J5 F, Q! v. m$ E7 f, L
! p) }3 L9 _4 A* m% m
+ g5 |" B/ `2 b# ` |
|