htaccess在子目录中重写(htaccess rewrite in subdirectory)
这可能是一个非常noob的问题,但我对网络开发相对较新,并且搜索了很多,但找不到像我这样的东西。 我有一个简单的htaccess。
RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^stores/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ stores/profile.php?sid=$1
这很好,就像我想要的那样
例如stores / profile.php?sid = 12被重写为
商店/ 12 /存储,搜索引擎优化名
在商店子目录中,我有一个页面显示每个商店列出的产品的详细信息,其中包含两个参数(store_id和product_id)我想像这样重写它
item_view.php?sid = 12&p_id = 35 to
项目/ 12/35 /产品SEO名
我尝试了很多方法,但我无法使它工作,当我在stores子目录中添加htaccess文件时,它给了我404错误。 任何帮助,将不胜感激。
This may be very noob question, but I am relatively new to web development and have googled a lot but could not found anything like mine. I have a simple htaccess.
RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^stores/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ stores/profile.php?sid=$1
this works just fine like I want it
e.g stores/profile.php?sid=12 is rewritten into
stores/12/store-seo-name
and in the stores sub directory,I have a page that displays details of a product listed by each store which takes two params (store_id & product_id) I want to rewrite it like this
item_view.php?sid=12&p_id=35 to
item/12/35/product-seo-name
I tried a lot of methods but I could not get it to work, and it gives me 404 error when I add htaccess file in the stores sub directory. Any help would be appreciated.
原文:https://stackoverflow.com/questions/43211669
最满意答案
编辑
从2011年8月8日
ggdendro
, CRAN上提供了ggdendro
软件包。另请注意,树状图提取功能现在称为dendro_data
而不是cluster_data
是的。 但是暂时你将不得不跳过一些箍:
- 安装
ggdendro
软件包(可从CRAN获得)。 该软件包将从Hclust
的绘图表达目的中提取来自几种类型聚类方法(包括Hclust
和dendrogram
)的聚类信息。- 使用网格图形创建视口并对齐三个不同的图。
代码:
首先加载库并设置ggplot的数据:
library(ggplot2) library(reshape2) library(ggdendro) data(mtcars) x <- as.matrix(scale(mtcars)) dd.col <- as.dendrogram(hclust(dist(x))) col.ord <- order.dendrogram(dd.col) dd.row <- as.dendrogram(hclust(dist(t(x)))) row.ord <- order.dendrogram(dd.row) xx <- scale(mtcars)[col.ord, row.ord] xx_names <- attr(xx, "dimnames") df <- as.data.frame(xx) colnames(df) <- xx_names[[2]] df$car <- xx_names[[1]] df$car <- with(df, factor(car, levels=car, ordered=TRUE)) mdf <- melt(df, id.vars="car")
提取树状图数据并创建图
ddata_x <- dendro_data(dd.row) ddata_y <- dendro_data(dd.col) ### Set up a blank theme theme_none <- theme( panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.title.x = element_text(colour=NA), axis.title.y = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank(), axis.line = element_blank() #axis.ticks.length = element_blank() ) ### Create plot components ### # Heatmap p1 <- ggplot(mdf, aes(x=variable, y=car)) + geom_tile(aes(fill=value)) + scale_fill_gradient2() # Dendrogram 1 p2 <- ggplot(segment(ddata_x)) + geom_segment(aes(x=x, y=y, xend=xend, yend=yend)) + theme_none + theme(axis.title.x=element_blank()) # Dendrogram 2 p3 <- ggplot(segment(ddata_y)) + geom_segment(aes(x=x, y=y, xend=xend, yend=yend)) + coord_flip() + theme_none
使用网格图形和一些手动对齐来定位页面上的三个图
### Draw graphic ### grid.newpage() print(p1, vp=viewport(0.8, 0.8, x=0.4, y=0.4)) print(p2, vp=viewport(0.52, 0.2, x=0.45, y=0.9)) print(p3, vp=viewport(0.2, 0.8, x=0.9, y=0.4))
EDIT
From 8 August 2011 the
ggdendro
package is available on CRAN Note also that the dendrogram extraction function is now calleddendro_data
instead ofcluster_data
Yes, it is. But for the time being you will have to jump through a few hoops:
- Install the
ggdendro
package (available from CRAN). This package will extract the cluster information from several types of cluster methods (includingHclust
anddendrogram
) with the express purpose of plotting inggplot
.- Use grid graphics to create viewports and align three different plots.
The code:
First load the libraries and set up the data for ggplot:
library(ggplot2) library(reshape2) library(ggdendro) data(mtcars) x <- as.matrix(scale(mtcars)) dd.col <- as.dendrogram(hclust(dist(x))) col.ord <- order.dendrogram(dd.col) dd.row <- as.dendrogram(hclust(dist(t(x)))) row.ord <- order.dendrogram(dd.row) xx <- scale(mtcars)[col.ord, row.ord] xx_names <- attr(xx, "dimnames") df <- as.data.frame(xx) colnames(df) <- xx_names[[2]] df$car <- xx_names[[1]] df$car <- with(df, factor(car, levels=car, ordered=TRUE)) mdf <- melt(df, id.vars="car")
Extract dendrogram data and create the plots
ddata_x <- dendro_data(dd.row) ddata_y <- dendro_data(dd.col) ### Set up a blank theme theme_none <- theme( panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.title.x = element_text(colour=NA), axis.title.y = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank(), axis.line = element_blank() #axis.ticks.length = element_blank() ) ### Create plot components ### # Heatmap p1 <- ggplot(mdf, aes(x=variable, y=car)) + geom_tile(aes(fill=value)) + scale_fill_gradient2() # Dendrogram 1 p2 <- ggplot(segment(ddata_x)) + geom_segment(aes(x=x, y=y, xend=xend, yend=yend)) + theme_none + theme(axis.title.x=element_blank()) # Dendrogram 2 p3 <- ggplot(segment(ddata_y)) + geom_segment(aes(x=x, y=y, xend=xend, yend=yend)) + coord_flip() + theme_none
Use grid graphics and some manual alignment to position the three plots on the page
### Draw graphic ### grid.newpage() print(p1, vp=viewport(0.8, 0.8, x=0.4, y=0.4)) print(p2, vp=viewport(0.52, 0.2, x=0.45, y=0.9)) print(p3, vp=viewport(0.2, 0.8, x=0.9, y=0.4))
相关问答
更多-
正确地扩展ggplot2?(Extending ggplot2 properly?)[2022-06-26]
ggplot2正在逐渐变得越来越可扩展。 开发版本https://github.com/hadley/ggplot2/tree/develop使用roxygen2(而不是两个独立的自制系统),并已经开始从原型转换到更简单的S3类(目前已完成协调和缩放) 。 这两个改变应该有希望使源代码更容易理解,并且因此更容易让其他人扩展(通过对ggplot2的拉取请求增加的事实来备份)。 Kohske Takahashi对指南系统的改进( https://github.com/kohske/ggplot2/tree/fe ... -
编辑 从2011年8月8日ggdendro , CRAN上提供了ggdendro软件包。另请注意,树状图提取功能现在称为dendro_data而不是cluster_data 是的。 但是暂时你将不得不跳过一些箍: 安装ggdendro软件包(可从CRAN获得)。 该软件包将从Hclust的绘图表达目的中提取来自几种类型聚类方法(包括Hclust和dendrogram )的聚类信息。 使用网格图形创建视口并对齐三个不同的图。 代码: 首先加载库并设置ggplot的数据: library(ggplot2) li ...
-
library("ggplot2") p <- ggplot(data=as.data.frame(G), aes(V1, V2)) + geom_vline(xintercept=0, colour="green", linetype=2, size=1) + geom_hline(yintercept=0, colour="green", linetype=2, size=1) + geom_point() + ...
-
在我看来,处理绘图的宽度和高度可以是一个简单而有价值的解决方案。 library(ggplot2) library(dendextend) data(iris) df <- iris[sample(150, 20), -5] ## Add blanks before "Longname_" labs <- paste(" Longname_", 1:20, sep = "") rownames(df) <- labs dend <- df %>% dist %>% hclust %>% as. ...
-
R中多个图形类型的对齐(最好是ggplot2或格子)(alignment of multiple graph types in R (preferably in ggplot2 or lattice))[2022-07-28]
使用lattice,set scales=list(relation="free") - 这会给你一个levelplot()的警告,但是对齐仍然可以正常工作。 如果你想要它超对齐,在levelplot()设置space="top" ,以使图例从热图的右侧移动到顶部。 更新 :我重置了一些填充和删除标签,如OP请求。 library(lattice) library(gridExtra) #within `scales` you can manipulate different parameters of x ... -
在ggplot2中扩展一个图形(Embiggening a graph in ggplot2)[2022-12-13]
使用ggsave并指定你想要的dpi 。 library(ggplot2) df <- data.frame(x = 1:10, y = rnorm(10)) my_plot <- ggplot(df, aes(x,y)) + geom_point(size = 4) ggsave(my_plot, file="sample.jpg", dpi = 600) Use ggsave and specify the dpi you desire. library(ggplot2) df <- data.fra ... -
使用dplyr没有意义。 您所要做的就是订购estimates ,提取相应的locations并将其传递给scale_x_discrete ,例如: scale_x_discrete(limits = Data$locations[order(Data$estimates)]) library(ggplot2) ggplot(Data, aes(locations, weight = estimates))+ geom_bar()+ coord_flip() + ...
-
在ggplot2图下注释(Annotate below a ggplot2 graph)[2022-03-13]
在我的回答中,我改变了几件事:1 - 我将数据名称更改为“df”,因为“数据”可能导致对象和参数之间的混淆。 2 - 我删除了主数据图上的额外面板空间,以便注释不那么远。 require(ggplot2) require(grid) require(gridExtra) # make the data df <- data.frame(y = -log10(runif(100)), x = 1:100) p <- ggplot(data=df, aes(x, y)) + geom_point() # ... -
这是可能的,但你需要首先编辑dendextend:::ggplot.ggdend以使其接受angle审美(以及hjust和vjust ) 第1步:编辑dendextend:::ggplot.ggdend newggplot.ggdend <- function (data, segments = TRUE, labels = TRUE, nodes = TRUE, horiz = FALSE, theme = theme_dendro(), offset_labels = 0, ... ...
-
正如问题所述,有一个问题与drm改组因子水平的顺序有关。 对这个烂摊子进行彻底洗牌证明比我预期的更棘手。 最后,我通过在每个因子级别调用drm函数来接近这个,以便一次构建一个因子级别的结果表。 这样做的这种冗长的方式揭示了plot.drc和ggplot版本的第一个图都不正确的事实。 让我们首先将函数调用包装到另一个包装函数中的drm() ,以便为每个跟踪重复调用它: drcmod <- function(dt1){ drm(formula = Germinated ~ Start + End ...