VPS侦探论坛

 找回密码
 注册
查看: 4986|回复: 4

请教网站的conf配置URL自定义重写吗?

[复制链接]
发表于 2013-8-13 22:03:42 | 显示全部楼层 |阅读模式

军哥,我用的Ecshop,
因为在默认规则中重写是goods-(数字id)-(产品名).html,,公司的人喜欢把url改得不一样,在.htaccess我们通过修改成以下格式来达到url中添加一些关键字,(这个站解析url的PHP也有相应修改)



  1. #RewriteRule ^goods-([0-9]+)(.*)\.html$  goods\.php\?id=$1 [QSA,L]
  2. RewriteRule ^cheap-(.*)-([0-9]+)\.html$  goods\.php\?id=$2 [QSA,L]
复制代码



这种方法的重写可以在conf中实现吗?  先谢谢了!
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2013-8-14 09:17:14 | 显示全部楼层


http://www.anilcetin.com/convert-apache-htaccess-to-nginx/ 转换后试试
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2013-8-16 17:44:18 | 显示全部楼层

我转换了还是不行,我把ecshop.conf这个文件改成了我对应的那个规则
  1. if (!-e $request_filename)
  2. {
  3. rewrite "^/index\.html" /index.php last;
  4. rewrite "^/category$" /index.php last;
  5. rewrite "^/feed-c([0-9]+)\.xml$" /feed.php?cat=$1 last;
  6. rewrite "^/feed-b([0-9]+)\.xml$" /feed.php?brand=$1 last;
  7. rewrite "^/feed\.xml$" /feed.php last;
  8. rewrite "^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 last;
  9. rewrite "^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 last;
  10. rewrite "^/category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /category.php?id=$1&brand=$2&page=$3&sort=$4&order=$5 last;
  11. rewrite "^/category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$" /category.php?id=$1&brand=$2&page=$3 last;
  12. rewrite "^/category-([0-9]+)-b([0-9]+)(.*)\.html$" /category.php?id=$1&brand=$2 last;
  13. rewrite "^/cheap-(.*)-golf-clubs-for-sale_([0-9]+)\.html$" /category.php?id=$2 last;
  14. rewrite "^/cheap-(.*)-for-sale_([0-9]+)\.html" /goods.php?id=$2 last;
  15. rewrite "^/article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /article_cat.php?id=$1&page=$2&sort=$3&order=$4 last;
  16. rewrite "^/article_cat-([0-9]+)-([0-9]+)(.*)\.html$" /article_cat.php?id=$1&page=$2 last;
  17. rewrite "^/article_cat-([0-9]+)(.*)\.html$" /article_cat.php?id=$1 last;
  18. rewrite "^/article-([0-9]+)(.*)\.html$" /article.php?id=$1 last;
  19. rewrite "^/brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html" /brand.php?id=$1&cat=$2&page=$3&sort=$4&order=$5 last;
  20. rewrite "^/brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html" /brand.php?id=$1&cat=$2&page=$3 last;
  21. rewrite "^/brand-([0-9]+)-c([0-9]+)(.*)\.html" /brand.php?id=$1&cat=$2 last;
  22. rewrite "^/brand-([0-9]+)(.*)\.html" /brand.php?id=$1 last;
  23. rewrite "^/tag-(.*)\.html" /search.php?keywords=$1 last;
  24. rewrite "^/snatch-([0-9]+)\.html$" /snatch.php?id=$1 last;
  25. rewrite "^/group_buy-([0-9]+)\.html$" /group_buy.php?act=view&id=$1 last;
  26. rewrite "^/auction-([0-9]+)\.html$" /auction.php?act=view&id=$1 last;
  27. rewrite "^/exchange-id([0-9]+)(.*)\.html$" /exchange.php?id=$1&act=view last;
  28. rewrite "^/exchange-([0-9]+)-min([0-9]+)-max([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /exchange.php?cat_id=$1&integral_min=$2&integral_max=$3&page=$4&sort=$5&order=$6 last;
  29. rewrite ^/exchange-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /exchange.php?cat_id=$1&page=$2&sort=$3&order=$4 last;
  30. rewrite "^/exchange-([0-9]+)-([0-9]+)(.*)\.html$" /exchange.php?cat_id=$1&page=$2 last;
  31. rewrite "^/exchange-([0-9]+)(.*)\.html$" /exchange.php?cat_id=$1 last;
  32. }
复制代码


但是这样又只能使用这一个站,其他站不同的URL规则却又不行,请问军哥,可以在vhost里的conf中进行配置吗?
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2013-8-16 17:45:39 | 显示全部楼层



上面说的是我把
  1. rewrite "^/category-([0-9]+)(.*)\.html$" /category.php?id=$1 last;
  2. rewrite "^/goods-([0-9]+)(.*)\.html" /goods.php?id=$1 last;
复制代码



改为了:

  1. rewrite "^/cheap-(.*)-golf-clubs-for-sale_([0-9]+)\.html$" /category.php?id=$2 last;
  2. rewrite "^/cheap-(.*)-for-sale_([0-9]+)\.html" /goods.php?id=$2 last;
复制代码



以符合这一个站的使用情况!
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2013-8-19 11:44:12 | 显示全部楼层

我在网上搜索了下,在www.xxx.com.conf这个文件里添加了一句代码解决了我帖子里的问题,希望能帮到以后同样的问题的朋友
  1. if ( !-e $request_filename)
  2.     {
  3.         rewrite "^/cheap-(.*)-golf-clubs-for-sale_([0-9]+)\.html$" /category.php?id=$2 last;                                
  4.         rewrite "^/cheap-(.*)-for-sale_([0-9]+)\.html" /goods.php?id=$2 last;                        
  5.     }
复制代码




不知道这是不是最优的,但是实现我想要的功能!

[ 本帖最后由 stanley178 于 2013-8-19 11:47 编辑 ]

军哥运维代购:http://shop63846532.taobao.com/

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-24 23:21 , Processed in 0.027706 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表