请教网站的conf配置URL自定义重写吗?
军哥,我用的Ecshop,因为在默认规则中重写是goods-(数字id)-(产品名).html,,公司的人喜欢把url改得不一样,在.htaccess我们通过修改成以下格式来达到url中添加一些关键字,(这个站解析url的PHP也有相应修改)#RewriteRule ^goods-(+)(.*)\.html$goods\.php\?id=$1
RewriteRule ^cheap-(.*)-(+)\.html$goods\.php\?id=$2
这种方法的重写可以在conf中实现吗?先谢谢了! http://www.anilcetin.com/convert-apache-htaccess-to-nginx/ 转换后试试 我转换了还是不行,我把ecshop.conf这个文件改成了我对应的那个规则if (!-e $request_filename)
{
rewrite "^/index\.html" /index.php last;
rewrite "^/category$" /index.php last;
rewrite "^/feed-c(+)\.xml$" /feed.php?cat=$1 last;
rewrite "^/feed-b(+)\.xml$" /feed.php?brand=$1 last;
rewrite "^/feed\.xml$" /feed.php last;
rewrite "^/category-(+)-b(+)-min(+)-max(+)-attr([^-]*)-(+)-(.+)-(+)(.*)\.html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 last;
rewrite "^/category-(+)-b(+)-min(+)-max(+)-attr([^-]*)(.*)\.html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 last;
rewrite "^/category-(+)-b(+)-(+)-(.+)-(+)(.*)\.html$" /category.php?id=$1&brand=$2&page=$3&sort=$4&order=$5 last;
rewrite "^/category-(+)-b(+)-(+)(.*)\.html$" /category.php?id=$1&brand=$2&page=$3 last;
rewrite "^/category-(+)-b(+)(.*)\.html$" /category.php?id=$1&brand=$2 last;
rewrite "^/cheap-(.*)-golf-clubs-for-sale_(+)\.html$" /category.php?id=$2 last;
rewrite "^/cheap-(.*)-for-sale_(+)\.html" /goods.php?id=$2 last;
rewrite "^/article_cat-(+)-(+)-(.+)-(+)(.*)\.html$" /article_cat.php?id=$1&page=$2&sort=$3&order=$4 last;
rewrite "^/article_cat-(+)-(+)(.*)\.html$" /article_cat.php?id=$1&page=$2 last;
rewrite "^/article_cat-(+)(.*)\.html$" /article_cat.php?id=$1 last;
rewrite "^/article-(+)(.*)\.html$" /article.php?id=$1 last;
rewrite "^/brand-(+)-c(+)-(+)-(.+)-(+)\.html" /brand.php?id=$1&cat=$2&page=$3&sort=$4&order=$5 last;
rewrite "^/brand-(+)-c(+)-(+)(.*)\.html" /brand.php?id=$1&cat=$2&page=$3 last;
rewrite "^/brand-(+)-c(+)(.*)\.html" /brand.php?id=$1&cat=$2 last;
rewrite "^/brand-(+)(.*)\.html" /brand.php?id=$1 last;
rewrite "^/tag-(.*)\.html" /search.php?keywords=$1 last;
rewrite "^/snatch-(+)\.html$" /snatch.php?id=$1 last;
rewrite "^/group_buy-(+)\.html$" /group_buy.php?act=view&id=$1 last;
rewrite "^/auction-(+)\.html$" /auction.php?act=view&id=$1 last;
rewrite "^/exchange-id(+)(.*)\.html$" /exchange.php?id=$1&act=view last;
rewrite "^/exchange-(+)-min(+)-max(+)-(+)-(.+)-(+)(.*)\.html$" /exchange.php?cat_id=$1&integral_min=$2&integral_max=$3&page=$4&sort=$5&order=$6 last;
rewrite ^/exchange-(+)-(+)-(.+)-(+)(.*)\.html$" /exchange.php?cat_id=$1&page=$2&sort=$3&order=$4 last;
rewrite "^/exchange-(+)-(+)(.*)\.html$" /exchange.php?cat_id=$1&page=$2 last;
rewrite "^/exchange-(+)(.*)\.html$" /exchange.php?cat_id=$1 last;
}
但是这样又只能使用这一个站,其他站不同的URL规则却又不行,请问军哥,可以在vhost里的conf中进行配置吗? 上面说的是我把rewrite "^/category-(+)(.*)\.html$" /category.php?id=$1 last;
rewrite "^/goods-(+)(.*)\.html" /goods.php?id=$1 last;
改为了:
rewrite "^/cheap-(.*)-golf-clubs-for-sale_(+)\.html$" /category.php?id=$2 last;
rewrite "^/cheap-(.*)-for-sale_(+)\.html" /goods.php?id=$2 last;
以符合这一个站的使用情况! 我在网上搜索了下,在www.xxx.com.conf这个文件里添加了一句代码解决了我帖子里的问题,希望能帮到以后同样的问题的朋友
if ( !-e $request_filename)
{
rewrite "^/cheap-(.*)-golf-clubs-for-sale_(+)\.html$" /category.php?id=$2 last;
rewrite "^/cheap-(.*)-for-sale_(+)\.html" /goods.php?id=$2 last;
}
不知道这是不是最优的,但是实现我想要的功能!
[ 本帖最后由 stanley178 于 2013-8-19 11:47 编辑 ]
页:
[1]