首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.htaccess路由

.htaccess路由
EN

Stack Overflow用户
提问于 2010-06-23 17:17:10
回答 1查看 3.3K关注 0票数 0

我想用.htaccess创建我自己的路由系统,但是我有一些问题。

我的文件夹结构是:

.htaccess

\x{e76f}

维-控制器

5.主题

- domain.dk

. gfx

-风格

- html

我怎样才能使我的.htaccess正确?也使用路由?

我的.htaccess看起来是这样的:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-06-23 18:36:52

代码语言:javascript
复制
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]

这是我想要的答案:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3103903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档