Ⅰ 如何写nginx伪静态规则
location / {
rewrite wx-hot-id-88.html index.php?m=wx&a=hot&id=88 break;
}
你这种是固定,比如说其中有不固定的就这样写
rewrite ([a-z]{2})-hot-id-([0-9]+).html index.php?m=$1&a=hot&id=$2 break;
为静态的作用就是让网络收录你的网站的时候的URL是html样式,但是当用户通过网络访问过来的时候 ,自动跳转到正常的网站地址。
Ⅱ 如何配置nginx伪静态以支持ThinkPHP的PATHINFO模式
打开Nginx的配置文件 /usr/local/nginx/conf/nginx.conf
一般是在这个路径,根据你的安装路径可能有所变化。如果你配置了vhost,而且只需要你这一个vhost支持pathinfo的话,可以直接打开你的
vhost的配置文件。找到类似如下代码(不同版本的nginx可能稍有不同,但是相差不会很远):
location~.*.(php|php5)?$
{
#原有代码
}
修改成以下代码:
#去掉$是为了不匹配行末,即可以匹配.php/,以实现pathinfo
#如果你不需要用到php5后缀,也可以将其去掉
location~.php
{
#原有代码
#定义变量$path_info,用于存放pathinfo信息
set$path_info"";
#定义变量$real_script_name,用于存放真实地址
set$real_script_name$fastcgi_script_name;
#如果地址与引号内的正则表达式匹配
if($fastcgi_script_name~"^(.+?.php)(/.+)$"){
#将文件地址赋值给变量$real_script_name
set$real_script_name$1;
#将文件地址后的参数赋值给变量$path_info
set$path_info$2;
}
#配置fastcgi的一些参数
fastcgi_paramSCRIPT_FILENAME$document_root$real_script_name;
fastcgi_paramSCRIPT_NAME$real_script_name;
fastcgi_paramPATH_INFO$path_info;
}
这样,nginx服务器就可以支持pathinfo了。但是如果要支持ThinkPHP的URL_MODE设置为2的模式,还需要配置rewrite规则。找到access_log语句,在其上方加上以下语句:
#如果请求既不是一个文件,也不是一个目录,则执行一下重写规则
if(!-e$request_filename)
{
#地址作为将参数rewrite到index.php上。
rewrite^/(.*)$/index.php/$1;
#若是子目录则使用下面这句,将subdir改成目录名称即可。
#rewrite^/subdir/(.*)$/subdir/index.php/$1;
}
Ⅲ Nginx伪静态php设置方法
修改/etc/nginx/nginx.conf,tae的话可能在conf.d里边的virtual.conf,在server里边添加伪静态规则
python">location/{
indexindex.phpindex.htmlindex.htm;
rewrite^(.*)/item/([0-9]+).html$1/item.php?id=$2last;
}
大概是这样,规则要自己测试
Ⅳ phpcms伪静态在nginx怎么写
location / {
###以下为PHPCMS 伪静态化rewrite规则
rewrite ^(.*)show-([0-9]+)-([0-9]+)\.html$ $1/show.php?itemid=$2&page=$3;
rewrite ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1/list.php?catid=$2&page=$3;
rewrite ^(.*)show-([0-9]+)\.html$ $1/show.php?specialid=$2;
####以下为PHPWind 伪静态化rewrite规则
rewrite ^(.*)-htm-(.*)$ $1.php?$2 last;
rewrite ^(.*)/simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2 last;
}
Ⅳ thinkphp 伪静态 nginx 规则怎么设置
关于nginx的伪静态设置(案例)
server {
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /alidata/www/;
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php?s=/$1 last;
}
}
location ~ .*.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
# 以下是为了让Nginx支持PATH_INFO
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param script_FILENAME $document_root$real_script_name;
fastcgi_param script_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_connect_timeout 120;
fastcgi_send_timeout 120;
fastcgi_read_timeout 120;
fastcgi_buffers 8 128K;
fastcgi_buffer_size 128K;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*.(js|css)?$
{
expires 1h;
}
#伪静态规则
access_log /alidata/log/nginx/access/default.log;
}
Ⅵ 如何实现网站的伪静态,分别说一下nginx和apache的实现方式
Nginx下设置伪静态方法与Apache差不多,直接在nginx.conf (或者在对应的*.conf) 中找到需设置伪静态规则的服务器对应字段,在server{ location/{ } }中添加以下代码:
server{
listen80default_server;
server_name_;
location/{
root/usr/share/nginx/html;
indexindex.htmlindex.htm;
rewrite^(.*)list-([0-9]+)-([0-9]+).html$$1list.php?page=$2&id=$3;
}
}
添加后重启Nginx服务即可生效
apache
要使用httpd.conf文件来设置伪静态策略,我们可以直接在httpd.conf中写入如下代码,如果您的网站是配置在VirtualHost中,则将这段代码加到对应的<VirtualHost hostname>
<VirtualHost>
标签内:
<IfMolemod_rewrite.c>
#输入:list-123-456.html
#输出:list.php?page=123&id=456
RewriteEngineon
RewriteRule^(.*)list-([0-9]+)-([0-9]+).html$$1list.php?page=$1&id=$2
</IfMole>
添加完成后重启httpd服务后即可生效
Ⅶ Nginx伪静态规则怎么设置
1、输入以下命令
cd
/alidata/server/nginx/conf/rewrite再输入ll
看看是不是像下面截图的一样。
2、这些就是伪静态规则文件。我们打开phpwind.conf看看。
已经在rewrtie目录下配置了常见程序的伪静态规则。可以直接调用。
3、如果没有就按照程序名.conf的命名方式新建一个配置文件
配置文件搞清楚了,你可能会说好像网站伪静态还是没效果啊。别着急,因为伪静态规则是需要被网站配置文件调用才行的。
4、输入以下命令
cd
/alidata/server/nginx/conf/vhosts
进入到网站配置目录
5、打开配置文件
修改好伪静态调用文件
下面测试下我们配置的文件是否正确吧输入
nginx:
the
configuration
file
/alidata/server/nginx/conf/nginx.conf
syntax
is
ok
nginx:
configuration
file
/alidata/server/nginx/conf/nginx.conf
test
is
successful
如果出现以上两句话就说明配置成功了。下面重启下nginx就可以了。
Ⅷ phpStudy中nginx建DZ2.5怎么设置伪静态怎么都不成功
关于伪静态技术,最初是动态语言出现后为了解决用户访问的便利性和搜索蜘蛛的友好性。关于伪静态的组件有ISAPI_Rewrite、开源的IIRF等。但ISAPI_Rewrite Lite版只支持全局的httpd.conf的,不支持分布式的httpd.ini的,只有收费的Full版才支持分布式httpd.ini。现在我们知道,Nginx也能实现简单的伪静态。更多介绍伪静态可以参考
CI在Apache、Nginx上运行需要.htaccess配置文件,在IIS服务器上则需要web.config文件,CI的伪静态我们可以通过.htaccess里面的规则设定
RewriteEngine on
RewriteCond $1 !^(index\\.php|system\\.php|images|skin|js|ls|swfupload|attachment|application|robots\\.txt)
RewriteRule ^(.*)$ /fx/index.php/$1 [L]
注: RewriteRule ^(.*)$ /webdir/index.php/$1 [L]里的webdir是你的CI程序目录
Ⅸ nginx 的伪静态的写法
url是什么都是可以的,关键的是在nginx的配置中,把原url rewrite成为真正的url。
比如有一个location是这样配置的:
location/{
rootxxxx;
indexindex.php;
fastcgi_passxxx;
includefastcgi.conf;
//跳转规则
rewrite"^/t/index.php/([^?]+)/([^?]+)"/t/$1/$2break;
}
一般而言,在访问的url中不要暴漏一些部署的信息,因此,一个url完全可以用/Newsindex/index来访问,只需要在rewriet的时候,能够把这个url转给合适的php脚本去处理就可以了。
rewrite"/Newsindex/index"/t/Newsindex/indexbreak;
这样也能实现要求。
Ⅹ nginx伪静态规则
在nginx中,rewrite的规则一般是:
rewritepatternreplacement[flag];
1. 其中pattern是匹配制定的url,这里采用pcre的正则表达式的匹配规则来进行;
2. replacement表示把匹配到的pattern的url转发到replace表示的url;
nginx默认是会把原url的参数原封不动的挂在新url之后。如果想忽略参数,可以采用replacement?的形式。
3. flag主要包括break;last;permenant;等。
如问题,如果你的静态url为
/forumstatic?mod=.....
可以采用如下的规则:
rewrite"/^+forumstatic"/document_root/forum.phpbreak;
或者重写参数:只保留mod参数,并且把mod参数转成m参数
rewrite"/^+forumstatic"/document_root/forum.php?m=$arg_mod?break;