与“改写”在Apache2的工作问题 [英] problems working with 'rewrite' in apache2
问题描述
我的URL下面的列表改写:
1写网址
/产品/ 客户端 /
发送至
/basedir/system/index.php?client=cliente
2写入网址
/产品/ 客户端的index.php
发送至
/basedir/system/index.php?client=cliente
3写网址
/产品/ 客户端 /image/dir2/myimage.jpg
发送至
/ BASEDIR /系统/图片/ 客户端 /dir2/myimage.jpg
4的写网址
/产品/ 客户端 /image/dir2/more_x_dir/other.img
发送至
/ BASEDIR /系统/图片/ 客户端 /dir2/more_x_dir/other.img
使用这些规则我都或多或少地解决了点1和2:
RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^产品/([A-ZA-Z] +)$ /basedir/system/index.php?client=base=$1 [L,QSA]
重写规则^产品/([A-ZA-Z] +)/ $ /basedir/system/index.php?client=base=$1 [L,QSA]
重写规则^产品/([A-ZA-Z] +)/(。*)$ /basedir/system/index.php?client=$1 [L,QSA]
我的问题是在案件3和4,当我有一个CSS /图像的/ js文件。并且,当我有很多的目录,也可能是在多个目录的情况下,必须使每个人的规则,但我不知道怎么办。
非常感谢你。
修改
根据回答采纳了我的解决方案:
RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^产品/([A-ZA-Z] +)/ \(*)。(GIF | JPG | ICO | CSS | JS | TXT |拉链| XLS | DOC)$ /basedir/system/$2.$3 [ L,QSA]
重写规则^产品/([A-ZA-Z] +)$ /basedir/system/index.php?database=$1 [L,QSA]
重写规则^产品/([A-ZA-Z] +)/ $ /basedir/system/index.php?database=$1 [L,QSA]
重写规则^产品/([A-ZA-Z] +)/ index.php的$ /basedir/system/index.php?database=$1 [L,QSA]
重写规则^产品/([A-ZA-Z] +)/(。*)$ / BASEDIR /系统/ $ 2〜数据库= $ 1 [L,QSA]
我相信,你想要做的东西像下面,根据您的描述(我还是对你目前拥有的规则有点困惑)。我也让你有文件夹命名为前提图片
, CSS
和 JS
为每个客户端。
RewriteEngine叙述上
#改写图像/ CSS / JS其真实的文件
重写规则^产品/([^ /] +)/(图片| CSS | JS)/ $ / BASEDIR /系统/ $ 2 / $ 1 / $ 3 [L](*)。
#重写一切的index.php文件脚本
重写规则^产品/([^/]+)(/.+)?$ /basedir/system/index.php?client=$1 [QSA,L]
I have the following list of URLs to rewrite:
1 write url
/products/client/
send to
/basedir/system/index.php?client=cliente
2 write url
/product/client/index.php
send to
/basedir/system/index.php?client=cliente
3 write url
/products/client/image/dir2/myimage.jpg
send to
/basedir/system/image/client/dir2/myimage.jpg
4 write url
/products/client/image/dir2/more_x_dir/other.img
send to
/basedir/system/image/client/dir2/more_x_dir/other.img
With these rules I have more or less solved the points 1 and 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]
My problem is in cases 3 and 4 when I have files with css / image's / js. and also when I have many directories, it may be that in the case of many directories have to make a rule for everyone, but I do not know how.
thank you very much
Edit
my solution based on the answer accepted:
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]
I believe that you want to do something like the following, based on your description (I'm still a little confused about the rules that you currently have). I also make the assumption that you had folders named image
, css
, and js
for each client.
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]
这篇关于与“改写”在Apache2的工作问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!