2010-06-23 105 views
0

我想創建我自己的路由系統.htaccess,但我有一些問題。.htaccess路由

我的文件夾結構是:

的.htaccess
| - 系統
| - 控制器
| - 主題
| - domain.dk
| --- gfx
| ---風格
| --- html

我該如何讓我的.htaccess對不對?也使用路由?

.htaccess看起來是這樣的:

RewriteEngine On 

php_value zlib.output_compression 16386 

RewriteCond %{HTTP_HOST} ^www\.(.*) 
RewriteRule (.*) http://%1/$1 [R=301,L] 


RewriteRule ^api/(.*)?$   /system/api/$1 
RewriteRule ^image/(.*)?$  /theme/%{HTTP_HOST}/gfx/$1 
RewriteRule ^data/(.*)?$  /theme/%{HTTP_HOST}/data/$1 
RewriteRule ^style/(.*)?$  /theme/%{HTTP_HOST}/include/$1 
RewriteRule ^javascript/(.*)?$  /theme/%{HTTP_HOST}/include/$1 
RewriteRule ^files/(.*)?$  /theme/%{HTTP_HOST}/files/$1 

# Sitemap & robot building 
RewriteRule ^xml-sitemap  /system/sitemap.php 
RewriteRule ^sitemap.xml  /system/sitemap.php 
RewriteRule ^robots.txt   /theme/%{HTTP_HOST}/data/robot.txt 

# Selecetet lang 
RewriteRule ^l-([a-z]+)/([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)?$ /system/index.php?modul=$2&title=$3&lang=$1 
RewriteRule ^l-([a-z]+)/([a-zA-Z0-9\-_]+)?$  /system/cms.php?tag=$2&lang=$1 

# Bilinfo - modul 
# RewriteRule ^mBiler?$   /system/index.php?modul=bilinfo&method=cars 
# RewriteRule ^mBiler/ck([0-9]+)\-([a-zA-Z0-9\-_]+)?$ /system/index.php?modul=bilinfo&method=car_single_view&id=$1&title=$2 
# RewriteRule ^mBiler/c([0-9]+)\-([a-zA-Z0-9\-_]+)?$ /system/index.php?modul=bilinfo&method=cars_list_view&id=$1&title=$2 

# Customer modul rewirte here 
RewriteRule ^customer-page?$   /system/index.php?modul=customer&method=login_screen 
RewriteRule ^customer-option?$   /system/index.php?modul=customer&method=customer_option 
RewriteRule ^customer-view-invoice/([a-zA-Z0-9\-_]+)?$ /system/index.php?modul=customer&method=view_single_invoice&guid=$1 
RewriteRule ^invoice-cancel/([a-zA-Z0-9\-_]+)?$  /system/index.php?modul=customer&method=cancel_invoice&guid=$1 
RewriteRule ^customer-main?$   /system/index.php?modul=customer&method=customer_main 
RewriteRule ^customer-lose-password?$  /system/index.php?modul=customer&method=lose_password 
RewriteRule ^customer-logout?$   /system/index.php?modul=customer&method=customer_logout 

# Etrade modul rewirte here 
RewriteRule ^shopping-cart?$   /system/index.php?modul=etrade&method=shopping_cart 
RewriteRule ^cart-remove-product/([a-zA-Z0-9]+)?$ /system/index.php?modul=etrade&method=remove_product_from_shopping_cart&cartid=$1 
RewriteRule ^shopping-cart-customer?$  /system/index.php?modul=etrade&method=shopping_cart_customer 
RewriteRule ^shopping-cart-done?$  /system/index.php?modul=etrade&method=shopping_cart_done 
RewriteRule ^cat([0-9,]+)/([a-zA-Z0-9\-_]+)?$  /system/index.php?modul=etrade&method=category_product_list&id=$1&title=$2 
RewriteRule ^cat([0-9,]+)/([a-zA-Z0-9\-_]+)/sort-([a-zA-Z0-9\-_]+)?$ /system/index.php?modul=etrade&method=category_product_list&id=$1&title=$2&sort=$3 
RewriteRule ^product([0-9]+)/([a-zA-Z0-9\-_]+)?$ /system/index.php?modul=etrade&method=product_view&id=$1&title=$2 
RewriteRule ^product_search?$   /system/index.php?modul=etrade&method=search_product 

# Gateway payment 
RewriteRule ^gateway/status/([a-zA-Z0-9\-_]+)?$  /system/index.php?modul=gateway&method=status&customer_guid=$1 
RewriteRule ^gateway/callback/([a-zA-Z0-9\-_]+)?$ /system/index.php?modul=gateway&method=callback&customer_guid=$1 

# Actions 
RewriteRule ^actions/([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)?$ /system/actions.php?modul=$1&method=$2 

# Defualt lang 
RewriteRule ^([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)/t-([0-9]+)-([a-zA-Z0-9\-_]+)?$ /system/index.php?modul=$1&method=$2&id=$3tag=$4 
RewriteRule ^([a-zA-Z0-9\-_]+)/t-([0-9]+)-([a-zA-Z0-9\-_]+)?$ /system/index.php?modul=$1&id=$2tag=$3 
RewriteRule ^bl([0-9]+)-([a-zA-Z0-9\-_]+)?$  /system/blog_view.php?blog_id=$1 
RewriteRule ^gl([0-9]+)-([a-zA-Z0-9\-_]+)?$  /system/gallery_view.php?blog_id=$1 

RewriteRule ^([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_]+)?$  /system/index.php?modul=$1&method=$2 
RewriteRule ^pre\-([a-zA-Z0-9\-_]+)?$  /system/cms.php?tag=$1&preview=true 
RewriteRule ^([a-zA-Z0-9\-_]+)?$   /system/cms.php?tag=$1 

# Test .htaccess stuff. 
# RewriteCond $1 !^(index\.php|robots\.txt|images|css|js) 
# RewriteCond %{REQUEST_FILENAME} !-f 
# RewriteCond %{REQUEST_FILENAME} !-d 
# RewriteRule ^(.*)/$ index.php [L] 

我註釋掉了最後5行,因爲我真的不知道我怎麼可以從例如搞定這個問題遠gfx,風格等等。我不希望用戶知道gfx的長URL是theme/domain.dk/gfx/images.png;他們需要看到它作爲gfx/images.png

+0

@contagious的拼寫錯誤是在代碼中太;對於接下來維持這一點的人來說,我感到相當不好 – 2010-06-23 17:28:50

回答

0
RewriteEngine On 

php_value zlib.output_compression 16386 

RewriteCond %{HTTP_HOST} ^www\.(.*) 
RewriteRule (.*) http://%1/$1 [R=301,L] 

# Test .htaccess stuff. 
RewriteRule ^image/(.*)?$        /theme/%{HTTP_HOST}/gfx/$1 [L] 
RewriteRule ^api/(.*)?$         /system/api/$1 [L] 
RewriteRule ^data/(.*)?$        /theme/%{HTTP_HOST}/data/$1 [L] 
RewriteRule ^javascript/(.*)?$       /theme/%{HTTP_HOST}/include/$1 [L] 
RewriteRule ^files/(.*)?$        /theme/%{HTTP_HOST}/files/$1 [L] 
RewriteRule ^style/(.*)?$        /theme/%{HTTP_HOST}/include/$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php [L] 

它我的答案我需要的,:)