当前位置:首页 » 操作系统 » rewritelinux

rewritelinux

发布时间: 2022-10-21 06:17:01

‘壹’ 在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` 平滑重启即可生效。

热点内容
搭建服务器能使用nodejs开发吗 发布:2025-05-14 18:24:14 浏览:134
alook浏览器安卓哪个版本上网最快 发布:2025-05-14 18:22:33 浏览:455
sqldist 发布:2025-05-14 18:08:18 浏览:162
人行外管局编译 发布:2025-05-14 18:07:33 浏览:649
安卓手机如何使用大流量 发布:2025-05-14 17:47:34 浏览:82
精密模具编程 发布:2025-05-14 17:45:16 浏览:499
存储顺序和逻辑顺序有什么区别 发布:2025-05-14 17:44:30 浏览:275
安卓版设置里的隐身在哪里 发布:2025-05-14 17:35:16 浏览:333
linuxshell密码 发布:2025-05-14 17:21:11 浏览:200
安卓手机听筒在哪里关闭 发布:2025-05-14 17:16:20 浏览:456