rewritelinux
『壹』 在linux伺服器nginx環境下rewrite規則怎麼寫
Linux系統下Nginx Rewrite 規則:
if($host~*^(.*?).domain.com$)set$var_wupin_city$1;
set$var_wupin『1′;
if($host~*^qita.domain.com$)
set$var_wupin『0′;
if(!-f$document_root/market/$var_wupin_city/index.htm)
set$var_wupin『0′;
if($var_wupin~『1′)
rewrite^/wu/$/market/$var_wupin_city/index.htmlast;
}
『貳』 在linux伺服器nginx環境下rewrite規則怎麼寫
具體的要根據你的需求來寫,不過可以給你舉一個例子,例如把訪問/abc路徑的鏈接全部轉到abc.com站點去:
server {
...
location /abc {
rewrite ^(.*)$ <a href="http://abc.com last; " target="_blank">http://abc.com last; </a>
}
...
}
『叄』 在linux伺服器nginx環境下rewrite規則怎麼寫
一.正則表達式匹配,其中:
* ~ 為區分大小寫匹配
* ~* 為不區分大小寫匹配
* !~和!~*分別為區分大小寫不匹配及不區分大小寫不匹配
二.文件及目錄匹配,其中:
* -f和!-f用來判斷是否存在文件
* -d和!-d用來判斷是否存在目錄
* -e和!-e用來判斷是否存在文件或目錄
* -x和!-x用來判斷文件是否可執行
三.rewrite指令的最後一項參數為flag標記,flag標記有:
1.last 相當於apache裡面的[L]標記,表示rewrite。
2.break本條規則匹配完成後,終止匹配,不再匹配後面的規則。
3.redirect 返回302臨時重定向,瀏覽器地址會顯示跳轉後的URL地址。
4.permanent 返回301永久重定向,瀏覽器地址會顯示跳轉後的URL地址。
使用last和break實現URI重寫,瀏覽器地址欄不變。而且兩者有細微差別,使用alias指令必須用last標記;使用proxy_pass指令時,需要使用break標記。Last標記在本條rewrite規則執行完畢後,會對其所在server{......}標簽重新發起請求,而break標記則在本條規則匹配完成後,終止匹配。
例如:如果我們將類似URL/photo/123456 重定向到/path/to/photo/12/1234/123456.png
rewrite "/photo/([0-9]{2})([0-9]{2})([0-9]{2})"/path/to/photo/$1/$1$2/$1$2$3.png ;
四.NginxRewrite 規則相關指令
1.break指令
使用環境:server,location,if;
該指令的作用是完成當前的規則集,不再處理rewrite指令。
2.if指令
使用環境:server,location
該指令用於檢查一個條件是否符合,如果條件符合,則執行大括弧內的語句。If指令不支持嵌套,不支持多個條件&&和||處理。
『肆』 在linux伺服器nginx環境下rewrite規則怎麼寫
nginx虛擬主機配置實例
1、在/usr/local/nginx/conf/nginx.conf文件末尾加入虛擬主機配置,實例如下:
server
{
listen 80;
server_name your_domain_name
index index.html index.htm index.php;
root /wwwroot/your_web_directory
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
#include rewite rule file or you can directly write here
include rewrite.conf;
log_format hebaodanscom 『$remote_addr – $remote_user [$time_local] 「$request」 『
『$status $body_bytes_sent 「$http_referer」 『
『」$http_user_agent」 $http_x_forwarded_for』;
access_log /logs/hebaodanscom.log hebaodanscom;
}
2、vi /usr/local/nginx/conf/rewrite.conf 輸入以下規則:
location / {
if (!-e $request_filename)
{
#————START —————WORLDPRESS————
rewrite ^ /index.php last;
#————END —————WORLDPRESS————
#————————zen-cart start——————
# From Ultimate SEO URLs
rewrite "^(.*)-p-(.*).html" /index.php?main_page=proct_info&procts_id=$2&% last;
rewrite "^(.*)-c-(.*).html" /index.php?main_page=index&cPath=$2&% last;
rewrite "^(.*)-m-([0-9]+).html" /index.php?main_page=index&manufacturers_id=$2&% last;
rewrite "^(.*)-pi-([0-9]+).html" /index.php?main_page=popup_image&pID=$2&% last;
rewrite "^(.*)-pr-([0-9]+).html" /index.php?main_page=proct_reviews&procts_id=$2&% last;
rewrite "^(.*)-pri-([0-9]+).html" /index.php?main_page=proct_reviews_info&procts_id=$2&% last;
# For Open Operations Info Manager
rewrite "^(.*)-i-([0-9]+).html" /index.php?main_page=info_manager&pages_id=$2&% last;
# For dreamscape』s News & Articles Manager
rewrite "^news/?" /index.php?main_page=news&% last;
rewrite "^news/rss.xml" /index.php?main_page=news_rss&% last;
rewrite "^news/archive/?" /index.php?main_page=news_archive&% last;
rewrite "^news/([0-9]{4})-([0-9]{2})-([0-9]{2}).html" /index.php?main_page=news&date=$1-$2-$3&% last;
rewrite "^news/archive/([0-9]{4})-([0-9]{2}).html" /index.php?main_page=news_archive&date=$1-$2&% last;
rewrite "^news/(.*)-a-([0-9]+)-comments.html" /index.php?main_page=news_comments&article_id=$2&% last;
rewrite "^news/(.*)-a-([0-9]+).html" /index.php?main_page=news_article&article_id=$2&% last;
# All other pages
# Don』t rewrite real files or directories
#RewriteCond %{REQUEST_FILENAME} !-f [NC]
#RewriteCond %{REQUEST_FILENAME} !-d
rewrite "^(.*).html" /index.php?main_page=$1&% last;
#—————————-zen-cart end—————–
}
}
保存後,運行 kill -HUP `cat /usr/local/nginx/nginx.pid` 平滑重啟即可生效。
『伍』 linux上面怎麼給apache安裝rewrite模塊
你是什麼發行版的linux?我在我的centos上rewrite是已經安裝好的,你可以在apache的模塊目錄下找一下看有沒有mod_rewrite.so這個東西,有的話就已經安裝好了,配置一下就可以用。
『陸』 linux下rewrite無效果的問題
httpd.conf配置文件里AccessFileName 如何設置的?
『柒』 Linux主機下Apache如何使用rewrite模塊
榻餼齜槳�: 1. 需要在apache的配置文件httpd.conf中加入相應配置: Apache-1.3.x版本,在/usr/prima/apache_ssl/conf/httpd.conf里加入: LoadMole rewrite_mole libexec/mod_rewrite.so AddMole mod_rewrite.c Apache-2.x版本,在/etc/httpd/conf/httpd.conf里加入: LoadMole rewrite_mole moles/mod_rewrite.so 2. 重啟apache: Apache-1.3.x: /usr/prima/apache_ssl/bin/apachectl restart Apache-2.x: /etc/init.d/httpd restart 3. 在/usr/prima/etc/httpd/virtual.conf的需要.htaccess和rewrite功能的站點配置中加入: AllowOverride Options FileInfo 注意FileInfo,這是支持RewriteEngine的關鍵 4. 之後只需要用戶自行在需要.htaccess的目錄中配置.htaccess文件了,如需要用rewrite模塊,加入如下: RewriteEngine On [rewrite配置] 5. Windows下可以先將.htaccess內容寫入一個文本文件中,然後將此文本文件上傳到伺服器需要.htaccess的目錄中,改名為.htaccess即可。 按照以上配置,即可使用rewrite模塊。
『捌』 linux上面怎麼給apache安裝rewrite模塊
安裝這種模塊最好的方法就是在官方網站上下載源文件,解壓後查看裡面的README文件,按照裡面的指示安裝,基本上是98%成功率的。這種模塊一般是不會有現成的可安裝文件的,你可以找其它有這個模塊的人拷一個,可以工作的。另外,你的發行版是什麼?最好說一下,方便解決。系統自帶的更應該自帶了,一般有apache的版本都會安裝一些基本的模塊,rewrite還是很基礎的一個模塊。
『玖』 在linux伺服器nginx環境下rewrite規則怎麼寫
具體方法如下:
1、在/usr/local/nginx/conf/nginx.conf文件末尾加入虛擬主機配置,實例如下:
server
{
listen80;
server_namehttp://www.hebaodans.com;
indexindex.htmlindex.htmindex.php;
root/wwwroot/www.hebaodans.com;
location~.*.(php|php5)?$
{
#fastcgi_passunix:/tmp/php-cgi.sock;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
includefcgi.conf;
}
#
includerewrite.conf;
log_formathebaodanscom『$remote_addr–$remote_user[$time_local]「$request」『
『$status$body_bytes_sent「$http_referer」『
『」$http_user_agent」$http_x_forwarded_for』;
access_log/logs/hebaodanscom.loghebaodanscom;
}
2、vi /usr/local/nginx/conf/rewrite.conf 輸入以下規則:
location/{
if(!-e$request_filename)
{
#————START—————WORLDPRESS————
rewrite^/index.phplast;
#————END—————WORLDPRESS————
#————————zen-cartstart——————
#FromUltimateSEOURLs
rewrite"^(.*)-p-(.*).html"/index.php?main_page=proct_info&procts_id=$2&%last;
rewrite"^(.*)-c-(.*).html"/index.php?main_page=index&cPath=$2&%last;
rewrite"^(.*)-m-([0-9]+).html"/index.php?main_page=index&manufacturers_id=$2&%last;
rewrite"^(.*)-pi-([0-9]+).html"/index.php?main_page=popup_image&pID=$2&%last;
rewrite"^(.*)-pr-([0-9]+).html"/index.php?main_page=proct_reviews&procts_id=$2&%last;
rewrite"^(.*)-pri-([0-9]+).html"/index.php?main_page=proct_reviews_info&procts_id=$2&%last;
#ForOpenOperationsInfoManager
rewrite"^(.*)-i-([0-9]+).html"/index.php?main_page=info_manager&pages_id=$2&%last;
#Fordreamscape』sNews&ArticlesManager
rewrite"^news/?"/index.php?main_page=news&%last;
rewrite"^news/rss.xml"/index.php?main_page=news_rss&%last;
rewrite"^news/archive/?"/index.php?main_page=news_archive&%last;
rewrite"^news/([0-9]{4})-([0-9]{2})-([0-9]{2}).html"/index.php?main_page=news&date=$1-$2-$3&%last;
rewrite"^news/archive/([0-9]{4})-([0-9]{2}).html"/index.php?main_page=news_archive&date=$1-$2&%last;
rewrite"^news/(.*)-a-([0-9]+)-comments.html"/index.php?main_page=news_comments&article_id=$2&%last;
rewrite"^news/(.*)-a-([0-9]+).html"/index.php?main_page=news_article&article_id=$2&%last;
#Allotherpages
#Don』
#RewriteCond%{REQUEST_FILENAME}!-f[NC]
#RewriteCond%{REQUEST_FILENAME}!-d
rewrite"^(.*).html"/index.php?main_page=$1&%last;
#—————————-zen-cartend—————–
}
}
保存後,運行 kill -HUP `cat /usr/local/nginx/nginx.pid` 平滑重啟即可生效。