Articles of .htaccess

将htaccess转换为nginx

试图设置一个图像服务器,我把它们放在nginx的速度。 我正在重写很多代码,但之前的开发人员把它放在了混乱之中。 有人可以给我一个正确的方向将此转换为nginx? <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /art_preview/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^art_preview/(.*)_(.*)_(.*)_(.*)_(.*)_(.*).jpg$ /imagetest.php?image_code=$1&frame_code=$2&matte_code=$3&style=$4&width=$5&max_size=$6 [L] RewriteRule ^art_preview/([a-zA-Z0-9]{1,})_(\d{1,}).jpg$ /imagetest.php?image_code=$1&max_size=$2 [L] </IfModule>

将.htaccess转换为PHP脚本的Nginxconfiguration的问题

我有一个.htaccess文件,我试图转换,所以它可以在我的Nginx服务器上运行。 我有两个主要问题: 我不确定如何转换一些行 2.我不知道把Nginxconfiguration代码放在哪里 以下是我遇到的问题转换: Options All -Indexes RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?page_request=$1 [QSA,L] 我尝试了一些在线转换器,但他们似乎并没有工作。 另外,一旦我改变了线,我把它们放在哪里? 我假设我需要将它们放在/etc/nginx/sites-available/中的mysite.conf文件中,但是在那个文件中,我只是把它们放在server {}块中? 非常感谢您给我的任何帮助。 编辑:这是conf文件 server { listen 0.0.0.0:80; server_name www.subdomain.domain.tld subdomain.domain.tld; access_log /var/log/subdomain.domain.tld.log; location / { root /srv/www/subdomain.domain.tld/public_html; index index.html index.php; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /srv/www/subdomain.domain.tld/public_html$fastcgi_script_name; […]

使用重写规则从url中删除.php后,css和img文件有404

我有我的网站和nginx服务器的问题…..从我的url地址删除.php我有错误的每个图像和CSS文件404。 有我的整个configuration文件: server { listen 80; server_name example.com; return 301 $scheme://www.example.com$request_uri; } server { listen 80; root /usr/share/nginx/www; index index.php; server_name www.example.com; error_page 404 http://www.example.com/404.php; autoindex off; error_log /usr/share/nginx/www/nginx_error.log warn; location / { rewrite ^(.*)$ /$1.php; } location = / { rewrite ^ /index.php; } location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; } } […]

如何阻止通过IP访问一组url模式?

我一直试图阻止访问/admin和/admin/{anything}与pipe理不是一个物理子目录在银条,除了有限的一组IP地址,并提出了以下.htaccess文件部分大部分工作。 <IfModule mod_rewrite.c> SetEnv HTTP_MOD_REWRITE On RewriteEngine On RewriteBase '/' RewriteCond %{REQUEST_URI} ^(.*)?(admin/(.*)|admin)$ RewriteCond %{REMOTE_ADDR} !^(127\.0\.0\.1|216\.58\.208\.36)$ RewriteRule ^(.*)$ – [R=403,L] </IfModule> 不过有人指出,这不会阻止非重写的访问framework/main.php?url=admin和framework/main.php?url=admin/{anything} 在这条银条上面也可以通过不支持.htaccess的Nginx服务。 我怎样才能更新这个.htaccess部分以阻止非重写版本,以及如何在nginx中做同样的事情?

翻译的urlpath来查询nginx的参数

Url https://example.com/profile/chico必须被nginx理解为: https://example.com/profile/?username=chico ://example.com/profile/?username https://example.com/profile/?username=chico (当前工作的url)。 https://example.com/profile/目前也能正常工作,因为它目前parsing为index.php,没有用户名参数。 我现在有 location /profile/ { index /profile/index.php; } networking上有这么多不同的东西,我没有具体find我需要的东西。 也试过 location /profile/ { rewrite ^/profile/(.*)$ /profile/?username=$1; }

nginx重写html文件并添加尾部斜杠

我已经读了十几个rewite问题。 大多数问题都是.php,但是我有简单的.html文件,所以关于=> about.html。但是我不能得到nginx这样做: 接受有或没有“/”的url 将domain.com/about和domain.com/about/redirect到domain.com/about.html 添加尾部的斜杠到URL,所以如果我写的domain.com/about写它的domain.com/about/ 我已经尝试用这个代码rewrite ^/([a-zA-Z0-9]+)$ /$1.html; 但它给了我404错误以“/”结尾的URL。 也试过这个rewrite ^([a-zA-Z0-9]+)/?$ $1.html同样的错误。 有人build议我应该使用尝试try_files ? 我试过这也给出了一个500错误: location / { rewrite ^(.*)$ /%1 redirect; rewrite ^/([^\.]+)$ /$1.html break; } 我试图从这里build议转换apache到nginx(winginx.com)没有成功。 此代码不起作用。 我正在尝试redirect并添加尾部斜线: if (!-e $request_filename){ rewrite ^/(.*)/$ /$1 redirect; } if (!-e $request_filename){ rewrite ^/(.*[^/])$ /$1/ redirect; } 任何build议都会让我开心。

在Nginx的子目录中运行辅助PHP应用程序

我有一个build立在Kirby平面文件CMS上的网站,并且它在根目录中运行得很好,但是我试图让一个在上面的项目的子目录(称为crm )中运行的FlightPHP实例。 这个FlightPHP实例将处理表单提交,所以我需要能够正确映射url。 使用Apache和.htaccess,很简单: # make forms/crm links work RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^crm/(.*) crm/index.php [L] 我似乎无法得到这与Nginx的工作,这是我迄今为止: server { listen 80; listen [::]:80; root /var/www/mainsite; index index.php index.html index.htm; server_name mydomain.com; autoindex on; access_log off; # Kirby Specific Directories rewrite ^/site/(.*) /error permanent; rewrite ^/kirby/(.*) /error permanent; add_header X-UA-Compatible "IE=Edge,chrome=1"; location ~ […]

问题与www数据和组读取站点文件夹

我locking了一些权限,现在nginx无法看到我的网站 背景: 我使用mysite用户部署和运行CLI。 我希望mysite和www-data都能访问网站的文件夹mysite和www-data用户 都属于www数据组: root@dev:~# groups mysite mysite : mysite www-data root@dev:~# root@dev:~# groups www-data www-data : www-data 该文件夹(具有组权限) drwxrwx— 3 mysite www-data 4096 Jun 26 14:12 sites/ www数据试图去到它: root@dev:~# sudo -u www-data stat /home/mysite/sites/ stat: cannot stat '/home/mysite/sites/': Permission denied 万维网数据可以看到父文件夹罚款: root@dev:~# sudo -u www-data stat /home/ File: '/home/' Size: 4096 Blocks: 8 […]

将Apache .htaccess转换为Nginx

我有一个Magento插件的下面的.htaccess代码,有人可以帮我把它转换成有效的Nginx重写吗? 我正在经历一段非常艰难的时期。 这是一个插件,重写和cachingMagento的URL。 该模块的原始编辑不能帮助我。 我敢肯定有很多人在使用Nginx并想使用这个插件function! # static rewrite – home page RewriteCond %{HTTP_COOKIE} store=default RewriteCond %{HTTP_COOKIE} !artio_mturbo=.* RewriteCond %{REQUEST_URI} ^/magento/$ RewriteCond %{QUERY_STRING} !.+ RewriteCond /var/ww/var/turbocache/default.html -f RewriteRule .* var/turbocache/default.html [L] # static rewrite – other pages RewriteCond %{HTTP_COOKIE} store=default RewriteCond %{HTTP_COOKIE} !artio_mturbo=.* RewriteCond %{REQUEST_URI} /magento/(.*)\.html$ [NC] RewriteCond %{QUERY_STRING} !.+ RewriteCond /var/www/var/turbocache/magento/default/%1.html -f RewriteRule .* var/turbocache/magento/default/%1.html […]

URL重写在Nginx中不起作用

URL重写在Nginx中不起作用,操作系统是Ubuntu 12.4 Lts 当打开http://mvc.loc它正在工作,但是当我尝试打开http://mvc.loc/login不工作 404没有find nginx的/ 1.1.19 .htaccess <IfModule !mod_rewrite.c> ErrorDocument 500 "mod_rewrite must be enabled" </IfModule> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?u=$1 虚拟主机为mvc.loc server { listen 80; server_name mvc.loc; access_log /var/log/nginx/mvc.loc.access.log; error_log /var/log/nginx/mvc.loc.error.log; root /usr/share/nginx/www/mvc; index index.php; # use fastcgi for all php files # Are you sure you […]