購物車中還沒有商品,趕緊選購吧!

                  Apache服務器如何開啟偽靜態

                  發布日期:2015-11-04 閱讀:16671

                  思途CMS系統在Apache服務器上如何設置偽靜態

                   

                  環境:
                  系統 Windows
                  Apache 2.2


                  加載Rewrite模塊:


                  conf目錄下httpd.conf中找到


                  LoadModule rewrite_module modules/mod_rewrite.so



                  這句,去掉前邊的注釋符號“#”,或添加這句。


                  允許在任何目錄中使用“.htaccess”文件,將“AllowOverride”改成“All”(默認為“None”):


                  # AllowOverride controls what directives may be placed in .htaccess files.
                  # It can be “All”, “None”, or any combination of the keywords:
                  # Options FileInfo AuthConfig Limit
                  #
                  AllowOverride All


                   


                   


                  Windows系統下不能直接建立“.htaccess”文件,可以在命令行下使用“echo a> .htaccess”建立,然后使用記事本編輯。


                  Apache Rewrite模塊的簡單應用:
                  Rewrite
                  的所有判斷規則均基于Perl風格的正則表達式,通過以下基礎示例能寫出符合自己跳轉需求的代碼。


                  1、請求跳轉


                  目的是如果請求為.jsp文件,則跳轉至其它域名訪問。


                  例如:訪問www.clin003.com/a.php跳轉至b.clin003.com/b.php網頁,訪問www.clin003.com/news/index.php跳轉至b.clin003.com/news/index.php網頁


                  注意:不是使用HTML技術中的meta或者javascript方式,因為www.clin003.com/a.php這個文件并不存在,用的是Apache2.2服務器中的Rewrite模塊。


                  修改 .htaccessapche的配置文件httpd.conf文件,添加以下內容


                   


                  RewriteEngine on
                  #開啟Rewrite模塊
                  RewriteRule (.*).php$ http://b.clin003.com/$1.jsp [R=301,L,NC]
                  #
                  截獲所有.jsp請求,跳轉到http://b.clin003.com/加上原來的請求再加上.phpR=301301跳轉,Lrewrite規則到此終止,NC為不區分大小寫


                   


                   


                  2、域名跳轉


                  如果請求為old.clin003.com下的所有URL,跳轉至b.clin003.com


                   


                  RewriteEngine on
                  #開啟Rewrite模塊
                  RewriteCond %{REMOTE_HOST} ^old.studenthome.cn$ [NC]
                  #針對hostold.clin003.com的主機做處理,^為開始字符,$為結尾字符
                  RewriteRule (.*) http://b.clin003.com/$1 [R=301,L,NC]


                   


                   


                  3、防盜鏈


                  如果本網站的圖片不想讓其它網站調用,可以在 .htaccess或者apche的配置文件httpd.conf文件中添加以下內容


                   




                  代碼


                  RewriteEngine on
                  #開啟Rewrite模塊
                  RewriteCond %{HTTP_REFERER} !^$
                  #如果不是直接輸入圖片地址
                  RewriteCond %{HTTP_REFERER} !img.clin003.com$ [NC]
                  #且如果不是img.clin003.com所有子域名調用的
                  RewriteCond %{HTTP_REFERER} !img.clin003.com/(.*)$ [NC]
                  RewriteCond %{HTTP_REFERER} !zhuaxia.com [NC]
                  RewriteCond %{HTTP_REFERER} !google.com [NC]
                  RewriteCond %{HTTP_REFERER} !google.cn [NC]
                  RewriteCond %{HTTP_REFERER} !baidu.com [NC]
                  RewriteCond %{HTTP_REFERER} !feedsky.com [NC]
                  RewriteRule (.*).(jpg|jpeg|jpe|gif|bmp|png|wma|mp3|wav|avi|mp4|flv|swf)$ http:
                  //clin003.com/err.jpg [R=301,L,NC]
                  #
                  截獲所有.jpg.jpeg……請求,跳轉到http://clin003.com/err.jpg提示錯誤的圖片,注:該圖片不能在原域名下,也不能在該.htaccess文件有效控制的文件夾中




                   


                   


                  4、不需要定義.htaccess文件


                  Apache2confhttpd.conf 最后一行添加


                  RewriteEngine On
                  RewriteRule ^(.*)-htm-(.*)$ $1.php?$2


                   


                   


                  重啟Apache
                  登陸后臺開啟全偽


                   


                   




                   


                   


                  GDLinux主機安裝discuz 7.2的注意了


                  這個discuz官方給出的偽靜態規則


                   




                  代碼


                   RewriteEngine 模式打開
                  RewriteEngine On
                  修改以下語句中的 /discuz 為你的論壇目錄地址,如果程序放在根目錄中,請將 /discuz 修改為 /
                  RewriteBase /discuz
                  # Rewrite 系統規則請勿修改
                  RewriteRule ^archiver/((fid|tid)-[w-]+.html)$ archiver/index.php?$1
                  RewriteRule ^forum-([0-9]+)-([0-9]+).html$ forumdisplay.php?fid=$1&page=$2
                  RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+).html$ viewthread.php?tid=$1&extra=page%3D$3&page=$2
                  RewriteRule ^space-(username|uid)-(.+).html$ space.php?$1=$2
                  RewriteRule ^tag-(.+).html$ tag.php?name=$1




                   


                   


                  使用這個規則后,你會發現,點擊論壇右下角的網站地圖“Archiver”,只能看到板塊,不能打開板塊下的帖子


                  這是修改后的偽靜態規則:


                   


                   




                  代碼


                   RewriteEngine 模式打開
                  RewriteEngine On
                  修改以下語句中的 /discuz 為你的論壇目錄地址,如果程序放在根目錄中,請將 /discuz 修改為 /
                  RewriteBase /
                  # Rewrite 系統規則請勿修改
                  RewriteRule ^archiver/([a-z0-9-]+.html)$ archiver/index.php?$1
                  RewriteRule ^forum-([0-9]+)-([0-9]+).html$ forumdisplay.php?fid=$1&page=$2
                  RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+).html$ viewthread.php?tid=$1&extra=page%3D$3&page=$2
                  RewriteRule ^space-(username|uid)-(.+).html$ space.php?$1=$2
                  RewriteRule ^tag-(.+).html$ tag.php?name=$1





                  以上內容是否對您有幫助? 您的反饋信息提交成功,謝謝您的反饋!

                  會員評論

                  在線客服
                  微信咨詢
                  微信咨詢
                  現在咨詢,獲取演示賬號
                  企業logo小米
                  立即掃碼加我微信
                  電話咨詢
                  咨詢電話
                  028-61558715
                  預約演示
                  亚洲日韩一区二区三区成人_国产老熟女一区二区三区_亚洲一区二区三区福利视频_国产丝袜美腿一区二区三区

                                  违禁视频在线观看网站 | 亚洲香蕉aⅴ视频在线播放 在线97免费视频 | 亚洲欧美日韩综合另类一区 | 洲va久久久噜噜噜久久 | 亚洲精品福利在线观看 | 日本乱码伦十八在线观看 |