views:

24

answers:

1

I want to create my own routing system with .htaccess, but I have some problems.

My folder structure is:

.htaccess
|- system
|- controller
|- theme
| -- domain.dk
| --- gfx
| --- style
| --- html

How can I make my .htaccess right? Using routing too?

My .htaccess looks like this:

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]

I have uncommented the last 5 lines because I don't really know how I can get this problem away from e.g. gfx, style, and more. I don't want the user to know the long URL to gfx is theme/domain.dk/gfx/images.png; they need to see it as gfx/images.png

A: 
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]

Its my answer i need, :)

NeoNmaN