【问题标题】:problems working with 'rewrite' in apache2在 apache2 中使用“重写”的问题
【发布时间】:2010-09-03 23:15:38
【问题描述】:

我有以下要重写的 URL 列表:

1 写网址
/products/客户/

发送至
/basedir/system/index.php?client=cliente

2 写网址
/product/客户端/index.php

发送至
/basedir/system/index.php?client=cliente

3 写网址
/products/客户端/image/dir2/myimage.jpg

发送至
/basedir/system/image/客户端/dir2/myimage.jpg

4 写网址
/products/客户端/image/dir2/more_x_dir/other.img

发送至
/basedir/system/image/客户端/dir2/more_x_dir/other.img

通过这些规则,我或多或少地解决了第 1 点和第 2 点:

 RewriteEngine On

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d

 RewriteRule ^product/([a-zA-Z]+)$ /basedir/system/index.php?client=base=$1 [L,QSA]
 RewriteRule ^product/([a-zA-Z]+)/$ /basedir/system/index.php?client=base=$1 [L,QSA]
 RewriteRule ^product/([a-zA-Z]+)/(.*)$ /basedir/system/index.php?client=$1 [L,QSA]

我的问题是在案例 3 和 4 中,当我有带有 css / image's / js 的文件时。还有当我有很多目录的时候,可能在很多目录的情况下要为大家制定一个规则,但我不知道怎么做。

非常感谢

编辑

我的解决方案基于接受的答案:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^product/([a-zA-Z]+)/(.*)\.(gif|jpg|ico|css|js|txt|zip|xls|doc)$ /basedir/system/$2.$3 [L,QSA]
RewriteRule ^product/([a-zA-Z]+)$ /basedir/system/index.php?database=$1 [L,QSA]
RewriteRule ^product/([a-zA-Z]+)/$ /basedir/system/index.php?database=$1 [L,QSA]
RewriteRule ^product/([a-zA-Z]+)/index.php$ /basedir/system/index.php?database=$1 [L,QSA]
RewriteRule ^product/([a-zA-Z]+)/(.*)$ /basedir/system/$2?database=$1 [L,QSA]

【问题讨论】:

  • 也许只有我一个人(确实有可能),但我很难弄清楚你的实际问题是什么。
  • 为什么前两条规则的查询字符串?client=base=$1,而第三条规则的查询字符串client=$1
  • 我可以让多个客户访问服务并为每个客户收取不同的数据库费用

标签: apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

根据您的描述,我相信您想要执行以下操作(我对您目前拥有的规则仍然有些困惑)。我还假设每个客户端都有名为 imagecssjs 的文件夹。

RewriteEngine On

# Rewrite images/css/js to their real files
RewriteRule ^products/([^/]+)/(image|css|js)/(.*)$ /basedir/system/$2/$1/$3 [L]

# Rewrite everything else to the index.php script
RewriteRule ^products/([^/]+)(/.+)?$ /basedir/system/index.php?client=$1 [QSA,L]

【讨论】:

    猜你喜欢
    • 2011-11-25
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 2011-02-24
    • 2015-08-08
    • 2016-09-28
    • 2010-11-11
    • 1970-01-01
    相关资源
    最近更新 更多