導航:首頁 > IDC知識 > apacherewrite域名

apacherewrite域名

發布時間:2020-10-20 14:43:21

1、如何在Apache開啟Rewrite環境

ubuntu如何開啟Rewrite模塊

在終端輸入:
sudo a2enmod rewrite 開啟Rewrite模塊(停用模塊,使用 a2dismod)
sudo gedit /etc/apache2/sites-available/default 修改下面的地方
<Directory />
Options FollowSymLinks
AllowOverride None(修改為AllowOverride All)
</Directory>
<Directory "/var/orioner">
Options Indexes FollowSymLinks MultiViews
AllowOverride None(修改為AllowOverride All)
Order allow,deny
allow from all
</Directory>
最後sudo /etc/init.d/apache2 restart。
----------------------------------------------------
在網站下面建立.htaccess文件
修改.htaccess文件屬性 chmod -R 777 .htaccess

Windows如何開啟Rewrite模塊

環境:
系統 Windows
Apache 2.2
載入Rewrite模塊:
在conf目錄下httpd.conf中找到
LoadMole rewrite_mole moles/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」建立,然後使用記事本編輯。

CentOs開啟Apache的rewrite_mole

centos的配置文件放在: /etc/httpd/conf/httpd.conf
打開文件找到:
LoadMole rewrite_mole moles/mod_rewrite.so
將前面"#"去掉,如果不存在則添加上句。
如果你的網站是根目錄的話:找到
代碼如下
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
將上面的None改為All
如果你的站點不在根目錄,設置如下:
代碼如下
<Directory "/var/www/html/my_directory">
Order allow,deny
Allow from all
AllowOverride All
</Directory>
OK,然後重啟伺服器,service httpd restart ,這樣.htaccess就可以使用了。

出自:http://www.111cn.net/phper/apache/54086.htm

2、Apache .htaccess 設置域名重定向

可以在htaccess文件中添加下面的代碼,當訪問abc.com的時候會重定向到www.abc.com,當然也可以設置重定向到其它的域名。
<IfMole mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc.com$ [NC]
RewriteRule ^(.*)$ http://www.abc.com/$1 [R=301,L]
</IfMole>

3、apache rewrite域名不變

隱性URL轉發吧, rewite跳轉過去的,域名顯示會變

4、使用apache 的.htaccess 方式實現rewrite,目的實現一空間多個域名的網站,不同域名使用不同目錄。

也是叫這個,nginx 與 apache 的 rewrite 基本上沒什麼區別,甚至可以拿來直接用。

Nginx的Rewrite
經過網上查閱和測試,發現Nginx的Rewrite規則和Apache的Rewite規則差別不是很大,幾乎可以直接使用。比如在Apache中這樣寫規則
rewrite ^/([0-9]).html$ /viewthread.php?tid=$1 last;
而在Nginx中寫成這樣寫是無法啟動的,解決的辦法是加上兩個雙引號:
rewrite "^/([0-9]).html$" /viewthread.php?tid=$1 last;
同時將RewriteRule為Rewrite,基本就實現了Nginx的Rewrite規則到Apache的Rewite規則的轉換。

Rewrite的Flags
last - 基本上都用這個Flag。
break - 中止Rewirte,不在繼續匹配
redirect - 返回臨時重定向的HTTP狀態302
permanent - 返回永久重定向的HTTP狀態301

官方文檔請點擊這里,另外如果對於302,301這些狀態有疑問的,可以參考《301 Redirect 永久重定向的實現》

如果需要對Nginx配置防盜鏈的話,可以參考《Nginx的防盜鏈配置》

Discuz!在Nginx下的Rewrite
需要說明的是,下網上以前一直流傳的Rewrite都是有誤的。
下面的Rewrite中百分號前面多了個轉移字元「\」,這在Apache中是需要的,而在Nginx中則是不需要的。
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page\%3D$3&page=$2 last;
正確的應該是
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;
這個錯誤在基本上目前所有使用Nginx作為伺服器,並且開啟了Rewrite的網站上存在。包括Discuz!官方,目前已經給cnteacher反饋了。

完整正確的Discuz!在Nginx下的Rewrite如下:
rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last;
rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2 last;
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;
rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?$1=$2 last;
rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last;
break;

5、你好,向您咨詢一下apache rewrite 二級域名加二級目錄的相關問題,期望您能恢復。

不知道你說的是哪一個帖子。

6、怎麼配置apache讓網站域名www或者有二級域名。

空間的站點需要登錄空間控制面板操作,跟客戶端電腦基本沒有關系。
相關操作具體可以咨詢空間提供商。

7、Apache Rewrite url重定向功能的配置成功,但是在瀏覽器上改卻不行,說沒有這個文件,不是應該直接跳轉

Apache伺服器實現301 重定向
確保你主機提供商的Apache Rewrite Mole組件已經打開,這是實現301重定向功能的必要前提。多數情況下,這個組件未被激活,只要點擊激活就可以。進入伺服器上的httpd.conf文件,那麼你就可以自行激活這些組件了。打開httpd.conf文件,若出現錯誤,請在錯誤處返回,忽略下面這一行信息:LoadMole rewrite_mole moles/mod_rewrite.so
然後保存文件,重啟伺服器,按照下列步驟進行

從你網站的原文件夾中找出httpd.conf文件,將它下載到你機器中某個可以編輯該文件的文件夾中。
復制httpd.conf文件,保存到安全的地方—但不要編輯這個復制文件;需要舊版本httpd.conf文件時,以供使用;
打開下載在寫字板中的原httpd.conf文件
將下面代碼添加到httpd.conf文件中。用你自己網站的域名信息代替「183.1.2.3」,注意不要更改其他地方。RewriteEngine On
RewriteCond %{HTTP_HOST} ^183.1.2.3
RewriteRule (.*) http://183.1.2.3/$1 [R=301,L]
將更改的httpd.conf文件上傳到從你網站上下載它的原位置
上傳完成後,打開瀏覽器,訪問你網站的「183.1.2.3」的那個地址。如果.htaccess文件執行任務的話,瀏覽器的地址欄中會立即顯示出你的「183.1.2.3」的這個域名,那麼你已經被重定向到這個地址上了

8、請教apache rewrite設定到目錄

RewriteRule ^/$ /program/man

9、如何配置Apache的Rewrite規則實現二級域名的轉化

^RewriteEngine on
rewritecond %{http_host} ^abc.ideasbulb.com [nc]
  rewriterule ^(.*).ideasbulb.com(.*)$ ideasbulb.com/$1$2 [r=301,nc]

與apacherewrite域名相關的知識