让我通过例子来解释… 文件: /var/www/example.com/public/wp-content/cache/minify/.htaccess <IfModule mod_rewrite.c> # THIS WORKS… RewriteBase /wp-content/cache/minify/ RewriteRule /w3tc_rewrite_test$ ../../plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 [L] RewriteCond %{REQUEST_FILENAME}%{ENV:APPEND_EXT} -f RewriteRule (.*) $1%{ENV:APPEND_EXT} [L] RewriteRule ^(.+/[X]+\.css)$ ../../plugins/w3-total-cache/pub/minify.php?test_file=$1 [L] RewriteRule ^(.+\.(css|js))$ ../../plugins/w3-total-cache/pub/minify.php?file=$1 [L] </IfModule> 文件: /etc/apache2/httpd.conf <Directory /var/www/example.com/public> AllowOverride None Options -MultiViews […] <IfModule mod_rewrite.c> Options +FollowSymlinks # Options +SymLinksIfOwnerMatch RewriteEngine On # RewriteBase / </IfModule> […] <IfModule mod_rewrite.c> […]
我刚刚安装了一个moodle,它的主题是这样的: http://moodle.example.com/theme/styles.php/standard/1380191797/all nginx没有select那个对PHP文件的调用,并且用404代替。 我目前的重写技术围绕着/index.php引用, /index.php可能过时了,但是之前它已经在很多事情上做了很多工作。 这是我目前的configuration。 server { listen 80; server_name moodle.example.com; root /websites/sbmoodle/moodle; index index.php; location / { try_files $uri $uri/ /index.php$request_uri /index.php; } location ~ \.php($|/) { try_files $uri =404; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name$fastcgi_path_info; fastcgi_pass unix:/var/run/php5-fpm.sock; } } 现在我看看Stack Exchange的冷光,在它的末尾( \.php($|/) ),我觉得应该抓住这些。 但是nginx仍然需要404s。 为什么? 是的,我已经testing/theme/styles.php (没有以下path),它工作正常。
我需要设置nginx将“www.test.com”重写为“www.new-test.com/test/test?foo=bar&bar=foo”。 我试过下面的代码: server { listen 80; server_name test.com www.test.com; access_log off; autoindex off; location / { rewrite ^ http://www.new-test.com/dir/test?foo=bar&bar=foo permanent; } } 我的问题是:“如果在重写结束时指定了?,那么Nginx将放弃原始的$ args”。 好吧,但我需要redirect到与查询完整的URL。 我怎样才能正确地做到这一点?
在网站维护期间,有时需要closures我们的网站。 我们目前的方法是touch一个将触发Web服务器( nginx )的文件,将stream量redirect到Amazon S3中托pipe的维护页面。 将维护页面托pipe在外部服务器上很重要,因为在维护期间不能保证任何本地文件的可用性。 这是我们用于“维护模式”的nginxconfiguration: server { … # Redirect processing of 503 error pages into a named location: error_page 503 @maintenance; # "Maintenance Mode" is off by default – Use a nginx variable to track state. set $maintenance off; # Swith on "Maintenace Mode" if a certain file exists. if (-f /var/www/mysite/shared/maintenanceON) […]
我在NGiNX中用正则expression式重写了一些问题。 这是我的configuration: location /wiki/ { rewrite ^/([^?]*)/([^?]*)(?:\?(.*))? /$1/index.php?title=$2&$3 last; } 以下是主页的URL://example.com/wiki/en/Main_Page 我有两个问题。 首先,当我去到这个URL://example.com/wiki/en 它说这个页面不存在。 有没有办法强制在url的末尾添加“en”的结尾? 因为如果你去//example.com/wiki/en/用/在最后 第二个问题: 图像未加载。 以下是MediaWiki图片位置的URL://example.com/wiki/en/skins/common/images/ 图片名称 那么有没有办法让我的正则expression式忽略的URL,如果它试图获取图像?
我在nginx反向代理背后的不同机器上有一个wordpress站点。 远程主机是10.0.1.1/kehitys/testi/wordpress,我想将其作为www.host.com/提供。 有没有什么办法可以configurationnginx从URL中删除/ kehitys / testi / wordpress /,并由远程服务器返回? 我的configuration如下所示: location / { rewrite /(.*) /kehitys/testi/wordpress/$1 break; proxy_pass http://10.0.1.10; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_redirect http://10.0.1.10/kehitys/testi/wordpress/ /; proxy_bind 10.0.1.1; proxy_pass_header Set-Cookie; }
我有像example.com/page.php?username=test这样的url。 我想重写这个url到像这样的: example.com/test只有当test遵循下面的正则expression式: /^[0-9a-zA-Z_-]{1,35}+$/ ,否则404页面。
我正在设置一个社交networking脚本,它有一个桌面和移动版本的网站。 当移动设备尝试浏览网站时,移动页面将与www.example.com/mobileurl一起提供。我想要.htaccess重写规则,可以将所有www.example.com/mobileurl更改为m.example。 com没有实际上redirect到子域这是我能想出的 RewriteCond %{HTTP_HOST} ^m.example.com RewriteRule (.*) http://www.example.com/mobile/$1 [R=301,L] 但我得到一个错误… Rewitecond: Bad flag delimiters如何解决这个问题或什么将是一个更好的方法来做到这一点? PS我没有一个.htaccess文件我直接在httpd.conf指令中设置这些规则。 我不认为这会有什么区别,只是认为最好提一下……以防万一。 我已经移动启用.htaccess并从httpd.conf文件采取重写规则,并testing如果。htaccess的作品,也是mod_rewrite启用。 我正在使用此代码来validationmod_rewrite是否确实启用 <?php ob_start(); phpinfo(INFO_MODULES); $contents = ob_get_contents(); ob_end_clean(); var_dump(strpos($contents, 'mod_rewrite') !== false); ?> 当我运行这个文件,我得到一个输出bool(true)还我注意到像下面的一个重写规则工作正常 # 301 redirect if missing www. RewriteCond %{HTTP_HOST} !^$ RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTPS}s ^on(s)| RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 但规则这些规则将无法正常工作 RewriteRule ^link([^/]*).html$ […]
我正在使用NGINX作为我的HTTP服务器从WordPress博客迁移到Jekyll博客,我不希望因为某些URL不能正常工作而中断互联网。 我到了一个我真的需要求助的地步。 原来的WordPress博客URL是这样的: example.com/series/ example.com/series/some-stuff/ 我想通过删除文件扩展名(.html)来模仿这个url,如果有人将WordPressurl存储在他的书签中,则回复一个非404网页。 没有任何重写的Jekyll默认URL是这样的: example.com/series/ –> This one is correct by default. example.com/series/some-stuff.html –> Not ok. 正如你可以看到第一个URL,系列部分已经确定,因为它是index.html页面,Jekyll在这种情况下隐藏了de文件名(如预期的那样),但是当你访问同一部分(/系列)中的任何其他页面获取扩展名的完整文件名。 好吧,我开始在重写工作中删除扩展名,并能够响应相同的WordPress的url,并在这里: rewrite ^/series/(.*)\.html*$ /series/$1 permanent; rewrite ^/series/(.*)/$ /series/$1 permanent; example.com/series/redirect到example.com/series/index –> It's working ok but I don't like that now it's showing me the file name (index). 其他人正在按我期望的方式工作,并正在响应旧的WordPress URls。 example.com/some-stuff.htmlredirect到example.com/series/some-stuff –> Correct! example.com/series/some-stuff/redirect到example.com/series/some-stuff –> Correct! […]
我有一个工作nginx重写的位置,但在一个特定的请求的情况下,我想重写到一个不同的位置。 location /api { if (!-e $request_filename){ rewrite "^/api/.{2}\.zip" /api/general.zip last; break; rewrite ^/api/(.*)$ /api/router.php?rest_data=$1 last; break; } } 所以如果有人要求/api/uk.zip,那么它下载的很好,但/api/fr.zip不存在,所以它应该redirect到/api/general.zip 我已经尝试了2个位置块,我得到了一个重复的位置错误,我试着用2个if语句,但是第二个被忽略。 如果请求是针对其他事情的,比如/ api / events,则应该转发到路由器页面。