rewrite

nginx 常见正则匹配符号表示

浪尽此生 提交于 2019-12-24 17:52:58
nginx 常见正则匹配符号表示 1 2 3 4 5 6 7 8 9 10 11 1、^: 匹配字符串的开始位置; 2、 $:匹配字符串的结束位置; 3、.*: .匹配任意字符,*匹配数量0到正无穷; 4、\. 斜杠用来转义,\.匹配 . 特殊使用方法,记住记性了; 5、(值1|值2|值3|值4):或匹配模式,例:(jpg|gif|png|bmp)匹配jpg或gif或png或bmp 6、i不区分大小写   一.正则表达式匹配,其中: * ~ 为区分大小写匹配 * ~* 为不区分大小写匹配 * !~和!~*分别为区分大小写不匹配及不区分大小写不匹配 二.文件及目录匹配,其中: * -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重写,浏览器地址栏不变。而且两者有细微差别

.htaccess Apache URL Rewrite for Wordpress - permanently pointing one domain to another

房东的猫 提交于 2019-12-24 17:23:46
问题 I am trying to point www.olddomain.com/whatever to www.newdomain.com/whatever (as well as without the www.), but the Wordpress permalinks are not staying intact. Please help!! <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] RewriteCond %{HTTP_HOST} ^olddomain.com [nc] RewriteRule ^(.*)$ http://www.newdomain.com/$1 [r=301,nc] RewriteCond %{HTTP_HOST} ^www.olddomain.com [nc] RewriteRule

htaccess redirect dynamic urls

南笙酒味 提交于 2019-12-24 16:56:46
问题 I am trying to write a htaccess redirect, but it is not working as I want it to. My current (working) htaccess redirects all html pages with 1 character to the index file as: RewriteRule ^([a-zA-Z0-9]).html$ index.php?letter=$1 So a.html gets redirected to index.php?letter=a Now I need to redirect the page a.html?page=2 to index.php?letter=a&page=2 Basically I want to redirect the url, but leave the dynamic part intact. All of the following return a 404: RewriteRule ^([a-zA-Z0-9]).html?page=(

Rewrite跳转

旧街凉风 提交于 2019-12-24 16:47:57
Nginx服务中Rewrite的应用 Rewrite跳转场景 URL看起来更规范、合理 企业会将动态URL地址伪装成静态地址提供服务 网址换新域名后,让旧的访问跳转到新的域名上 服务端某些业务调整 Rewrite跳转实现 Rewrite实用场景 Nginx跳转需求的实现方式 使用 rewrite 进行匹配跳转 使用 if 匹配全局变量后跳转 使用 location 匹配再跳转 rewrite放在server{},if{},location{} 段中 对域名或参数字符串 使用 if 全局变量匹配 使用 proxy_ pass 反向代理 Nginx正则表达式 常用的正则表达式元字符 字符 说明 ^ 匹配输入字符串的起始位置 $ 匹配输入字符串的结束位置 * 匹配前面的字符零次或多次 + 匹配前面的字符一次或多次 ? 匹配前面的字符零次或一次 . 匹配除“\n”之外的任何单个字符。使用诸如"[.\n]"之 类的模式,可匹配包括“n”在内的任意字符 \ 将后面接着的字符标记为一个特殊字符或一个原义字符或一个向后引用 \d 匹配纯数字 {n} 重复n次 {n,} 重复n次或更多次 [c] 匹配单个字符c [a-z] 匹配a-z小写字母的任意一个 [a-zA-Z] 匹配a-z小写字母或A-Z大写字母的任意一 个 Rewrite命令 语法 rewrite <regex> <replacement

URL Redirect based on client logged in

寵の児 提交于 2019-12-24 15:00:24
问题 How do I redirect url based on register client in c# .net or asp.net 4.0. For example if client registers as "client1" and our website is www.mycompany.com for every page client proceeds should get www.client1.mycompany.com. More detailed example: For example another client created is Client2. The pages i have created in general is like "www.mycompany.com/product.aspx" "www.mycompany.com/categories.aspx" should be shown as "www.client2.mycompany.com/product.aspx" and www.client2.mycompany.com

htaccess file: replace spaces with hypen + link to new url

笑着哭i 提交于 2019-12-24 10:35:44
问题 I'd like to replace any space in my URLs with a hypen This is my complete htaccess file: Options -MultiViews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php RewriteRule ^archive/([^/]+)$ news?title=$1 The problem is that my title often contains spaces so it returns this url: example.com/archive/this%20is%20a%20test Url that I'd like to create: example.com/archive/this-is-a-test I read that I could include a "\" to remove

url rewrite htaccess and php

北城以北 提交于 2019-12-24 10:29:50
问题 I want to rewrite URL and for that I have got following code. Options +FollowSymLinks RewriteEngine On RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?uname=$1 RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?uname=$1 now when I write url like www.mywebsite.com/username it works fine and not giving any error. Now how can I get this URL even when I write www.mywebsite.com/index.php?uname=username in hit go. I want to change www.mywebsite.com/index.php?uname=username to www.mywebsite.com/username when I

Hide Part of URL htaccess

半世苍凉 提交于 2019-12-24 09:28:18
问题 The Goal: The user lands on the site where the latest 10 articles are shown (no problem here). The user clicks on the title of one article using this href link in a table: <a href='"."article.php/".$type."/".$id."/".$web_title."'>".$title."</a> All links from any $type get directed to article.php . article.php should be built dynamically based on the $id retrieving information from the database. I've got this URL rewrite in my htaccess file: RewriteEngine On RewriteCond %{REQUEST_URI} ^

.htaccess file: Dynamic redirect

自闭症网瘾萝莉.ら 提交于 2019-12-24 07:38:36
问题 I've had a hard timing learning rewrite rules in .htaccess files, so I was hoping someone could show me how to rewrite this: test.com/home/feed/toak/nyheter/vg into this: test.com/index.php?r=home&f=feed;toak;nyheter;vg This is a dynamic URL, and can have multiple elements seperated by ; in the end. I want my users to be able to type in as human friendly URLs as possible. I'm hoping someone can help! 回答1: If you have variable number of parameters, you can't do it only with .htaccess. You

How to prevent two links show the same content with .htaccess?

我的梦境 提交于 2019-12-24 07:37:38
问题 I have this case: /css/ <-- a folder /css/something.css <-- a file If the user accesses the folder (/css/), I want that Apache returns the file. If the user tries to access the file directly, (/css/something.css), I want that he be redirected to the folder. How can I do this without getting a loop? I've read a lot but I couldn't figure it out applying two rules, it always returns a loop. Note: this is my first question on Stack Overflow. Thank you in advance. 回答1: Put these in your htaccess