首页 \ 问答 \ htaccess在子目录中重写(htaccess rewrite in subdirectory)

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
更新时间:2022-10-14 12:10

最满意答案

编辑

从2011年8月8日ggdendroCRAN上提供了ggdendro软件包。另请注意,树状图提取功能现在称为dendro_data而不是cluster_data


是的。 但是暂时你将不得不跳过一些箍:

  1. 安装ggdendro软件包(可从CRAN获得)。 该软件包将从Hclust的绘图表达目的中提取来自几种类型聚类方法(包括Hclustdendrogram )的聚类信息。
  2. 使用网格图形创建视口并对齐三个不同的图。

在这里输入图像描述

代码:

首先加载库并设置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 called dendro_data instead of cluster_data


Yes, it is. But for the time being you will have to jump through a few hoops:

  1. Install the ggdendro package (available from CRAN). This package will extract the cluster information from several types of cluster methods (including Hclust and dendrogram) with the express purpose of plotting in ggplot.
  2. Use grid graphics to create viewports and align three different plots.

enter image description here

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正在逐渐变得越来越可扩展。 开发版本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. ...
  • 使用lattice,set scales=list(relation="free") - 这会给你一个levelplot()的警告,但是对齐仍然可以正常工作。 如果你想要它超对齐,在levelplot()设置space="top" ,以使图例从热图的右侧移动到顶部。 更新 :我重置了一些填充和删除标签,如OP请求。 library(lattice) library(gridExtra) #within `scales` you can manipulate different parameters of x ...
  • 使用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() + ...
  • 在我的回答中,我改变了几件事: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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)