linuxrewrite
㈠ 在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` 平滑重啟即可生效。
㈡ Linux web怎麼設置只允許域名訪問
要實現只用域名訪問而不用IP訪問,要看所使用的web伺服器軟體,以nginx為例,可以通過如下方法進行設置:
1、用vim打開nginx的配置文件,一般為nginx/conf/nginx.conf
2、在server的設置裡面添加如下內容即可:
#禁止IP訪問
server{
listen 80 default;
server_name _;
return 500;
}
或者
server {
listen 80 fault;
server_name _;
rewrite ^(.*) http://域名 permanent;
}
㈢ linux apache配置文件怎麼沒有rewrite
Apache已經編譯安裝完了,上傳程序,發現必須得用rewrite,重新上載模塊。找到apache的源碼包安裝文件:# tar zxvf httpd-2.2.11.tar.gz# cd httpd-2.2.11/moles/mappers# /usr/local/apache2/bin/apxs -i -a -c ./mod_rewrite.c[root@el5 mappers]# /usr/local/apache2/bin/apxs -i -a -c ./mod_rewrite.c終端窗口提示信息:/usr/local/apache2/build/libtool --silent --mode=compile gcc -prefer-pic -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -g -O2 -pthread -I/usr/local/apache2/include -I/usr/local/apache2/include -I/usr/local/apache22/include -c -o ./mod_rewrite.lo ./mod_rewrite.c && touch ./mod_rewrite.slo/usr/local/apache2/build/libtool --silent --mode=link gcc -o ./mod_rewrite.la -rpath /usr/local/apache2/moles -mole -avoid-version ./mod_rewrite.lo/usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/local/apache2/build/libtool' ./mod_rewrite.la /usr/local/apache2/moles/usr/local/apache2/build/libtool --mode=install cp ./mod_rewrite.la /usr/local/apache2/moles/cp ./.libs/mod_rewrite.so /usr/local/apache2/moles/mod_rewrite.socp ./.libs/mod_rewrite.lai /usr/local/apache2/moles/mod_rewrite.lacp ./.libs/mod_rewrite.a /usr/local/apache2/moles/mod_rewrite.achmod 644 /usr/local/apache2/moles/mod_rewrite.aranlib /usr/local/apache2/moles/mod_rewrite.aPATH="$PATH:/sbin" ldconfig -n /usr/local/apach2/moles----------------------------------------------------------------------Libraries have been installed in: /usr/local/apache2/molesIf you ever happen to want to link against installed librariesin a given directory, LIBDIR, you must either use libtool, andspecify the full pathname of the library, or use the `-LLIBDIR'flag ring linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable ring execution - add LIBDIR to the `LD_RUN_PATH' environment variable ring linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf'See any operating system documentation about shared libraries formore information, such as the ld(1) and ld.so(8) manual pages.----------------------------------------------------------------------chmod 755 /usr/local/apache2/moles/mod_rewrite.so[activating mole `rewrite' in /usr/local/apache2/conf/httpd.conf]完成,通過提示信息看到rewrite庫文件已被安裝到/usr/local/apache2/moles目錄下。現在打開httpd.conf文件後就能找到這行了:LoadMole rewrite_mole moles/mod_rewrite.so重啟apache!