天道酬勤,学无止境

mod-rewrite

Mod_Rewrite 通配符的 / 附加(Mod_Rewrite wildcard's / appending)

问题 我正在尝试使用我网站上的类别制定全局规则,其中某些内容会自动添加到 url 的末尾。 一个例子: www.websitename.com/category/page.html 被更改为 www.websitename.com/category/page.html?somethingelse 并且随后是 www.websitename.com/category/* 的任何内容都附加了 ?somethingelse 我知道我可以用单独的 301 重定向来做到这一点,但有没有一条规则适用于所有人? 由于当前每次创建新页面时,都必须进行新的重定向。 回答1 如果我正确理解你,这应该可以解决问题: RewriteRule ^category/(.*.html)$ category/$1?somethingelse 这意味着每个以 category 开头并以 html 结尾的 URL 都将被重写以在末尾添加 ?somethingelse。 例子: http://www.websitename.com/category/foo.html => http://www.websitename.com/category/foo.html?somethingelse http://www.websitename.com/category/bar.html => http://www

2021-10-27 04:05:17    分类:技术分享    mod-rewrite

将 index 和 index.php 视为同一个文件(Treating index and index.php as the same file)

问题 我正在使用 Apache 2.2.22 和 PHP 5.3.10 处理 PHP 项目,但遇到了 index 和 index.php 被视为同一个文件的问题。 我有一个 admin/index.php,它重定向到 admin/index 以允许我在 .htaccess 中的 mod_rewrite 规则接管并将请求重新路由到自定义框架中。 问题是,当浏览器转到 admin/index 时,它会进入无限重定向循环,因为请求被发送到 admin/index.php,然后重定向到 admin/index 我已经尝试删除 htaccess 文件,看看我的 mod_rewrite 规则是否有问题导致它并且它没有改变任何东西。 它只是无休止地重定向到 admin/index。 我以前从未听说过这种行为,浏览一些 Google 结果并浏览 apache 配置文件并没有显示任何明显的东西。 有没有人以前见过这个并知道如何解决它? 编辑:下面是 index.php 用于重定向到索引的代码。 <?php header("Location: index"); die(); 回答1 这可能是由于启用了 MultiViews: MultiViews的作用如下:如果服务器收到/some/dir/foo的请求,如果/some/dir开启了MultiViews,而/some/dir/foo不存在

2021-10-27 04:01:54    分类:技术分享    php   apache   .htaccess   mod-rewrite   indexing

Redirect any page passing certain variables

I'm putting a search engine on my site, and the search box appears on several different pages. The output looks like this: http://mysite.com/mypage.php?bluepart=search&keywords=dogs&go=Go I'm trying to do an .htaccess mod rewrite to where any page that passes these variables will get redirected to search_results.php. The bluepart=search and go=Go will always be the same, but keywords can be any number or words. Also, some of my pages are .html and some are .php, when I refer to any page that passes the variables.

2021-10-27 03:46:04    分类:问答    php   .htaccess   mod-rewrite

Problems with RewriteMap MapType dbd

Continuing from another discussion here: MySQL + htaccess mod_rewrite? Where I was asked to start another question. I added this to my httpd.conf file: DBDriver mysql DBDParams "host=*****,user=*****,pass=*****,dbname=*****" RewriteEngine On RewriteMap hrci "dbd:SELECT title FROM challenges WHERE id = %s" When I tried to restart Apache I got this error: RewriteMap: file for map hrci not found:/dh/apache2/apache2-ps54462/dbd:SELECT title FROM challenges WHERE id = %s It looks like it's completely ignoring the dbd part and trying to read the whole thing as a file name. I really don't know what I

2021-10-27 01:57:39    分类:问答    mysql   .htaccess   mod-rewrite   rewritemap

Mod_Rewrite wildcard's / appending

I'm trying to make a global rule with a category on my website where something automatically gets added to the end of url. An example: www.websitename.com/category/page.html gets changed to www.websitename.com/category/page.html?somethingelse and anything subsequently which is www.websitename.com/category/* gets appended with ?somethingelse I know I could do this with individual 301 redirects but is there a one rule fits all? as every time a new page is created currently, a new redirect would have to be made.

2021-10-27 01:48:33    分类:问答    mod-rewrite

Why does this .htaccess RewriteRule that includes a '#' fail?

Goal: Match URL and rewrite it to a query string. Problem: Looks like the "#" (and everything after it) in the replacement string is being ignored. Here's what I have: RewriteEngine On RewriteRule ^([^\.]+)$ $1.html [NC,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/([^/]+) web2.html#list?d=$1&n=$2 [L,NE] This gets to web2.html but the url parameters (d= & n=) are never applied. The goal is to allow a url like: somewehere.com/55c26838e4b087b032b432c4/1/ to trigger a query like this: somewehere.com/web2#list?d=54668494e4b09ffed41ff167&n=1

2021-10-27 01:39:44    分类:问答    .htaccess   mod-rewrite

mod_rewrite 和图像重定向(mod_rewrite and image redirecting)

问题 我有一个有很多图片的网站。 假设这些图像存储在文件夹“/data/images”中。 我还有一个带有水印图像的文件夹:“/data/wimages”。 原始图像和水印图像的文件名相同,但并非所有图像都有其水印副本。 所以,如果水印副本存在,我想重定向原始图像(不更改其在浏览器或 html 源代码中的 URL),如果没有,则通过原始图像传递。 我正在尝试使用 Apache mod_rewrite 解决这个问题: RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f # Checking if file exists and is a regular file. RewriteCond %{REQUEST_URI} ^.*/data/images/.*\.(gif|jp?g|png)$ [NC] # Is file an image? RewriteRule ^data/images/(.*\.(gif|png|jp?g))$ /data/wimages/$1 [NC] # New watermaked image url. RewriteCond %{REQUEST_FILENAME} !-f # If watermarked image not exists .. RewriteRule ^data/wimages/(.*\

2021-10-26 21:40:48    分类:技术分享    apache   mod-rewrite

使用 Apache mod_rewrite 区分空 REQUEST_URI 的问题(Problem distinguishing empty REQUEST_URI with Apache mod_rewrite)

问题 与使用 Apache mod_rewrite 检测空 REQUEST_URI 的问题合并。 我正在使用这样的重定向规则运行 Apache: RewriteCond %{HTTP_HOST} ^1st-domain\.com RewriteRule ^(.*)$ http://2nd-domain.com$1 [R=permanent,L] 这成功地将 http://1st-domain.com 重定向到 http://2nd-domain.com 但是,当 REQUEST_URI 为空时,我想重定向到第三个域。 RewriteCond %{HTTP_HOST} ^1st-domain\.com$ RewriteCond %{QUERY_STRING} ^$ RewriteRule ^(.*)$ http://3rd-domain.com$1 [R=permanent,L] 但这不起作用,而是重定向到 2nd-domain.com 我的规则是这样排序的: RewriteCond %{HTTP_HOST} ^1st-domain\.com$ RewriteCond %{QUERY_STRING} ^$ RewriteRule ^(.*)$ http://3rd-domain.com$1 [R=permanent,L] RewriteCond %{HTTP_HOST} ^1st

2021-10-26 20:44:50    分类:技术分享    apache   url   mod-rewrite   url-rewriting

.htaccess basic url rewrites

There are a few things I want done to the URLs of my site that I cannot seem the .htaccess file to do. 1 remove file extension f.e. example.com/file.php should be example.com/file 2 remove the www. f.e. www.example.com should be example.com (I got this part to work, but I would hate it if after I put in fix and this no longer worked 3 no one should be able to see index.php at the end of root f.e. example.com/index.php should be example.com 4 my blog page should have nice urls f.e. example.com/blog.php?article=the-name-of-article should be example.com/blog/the-name-of-article here is my current

2021-10-26 20:19:45    分类:问答    apache   .htaccess   mod-rewrite

.htaccess pretty url problem (mod_rewrite)

I have a directory that lists products by categories. if a _GET variable exists, it is used in a query. I would like to use "pretty url's", like: example/a/1/b/2/c/3/d/4 becomes example/index.html?a=1&b=2&c=3&d=4 most .htaccess examples I see only use variables to replace the _GET values, but I can use rules like this: Options +FollowSymlinks RewriteEngine on RewriteRule ([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.html?$1=$2&$3=$4&$5=$6 [L] RewriteRule ([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.html?$1=$2&$3=$4 [L] RewriteRule ([^/]+)/([^/]+)$ index.html?$1=$2 [L] And it works

2021-10-26 20:12:21    分类:问答    apache   .htaccess   mod-rewrite   friendly-url