1

I'm kind of new to mod_rewrite so I need some help from you guys.

My folder structure is:

assets/fonts/       Contains all fonts
assets/images/      Contains all images
assets/scripts/     Contains all JavaScript files
assets/styles/      Contains all CSS files
pages/              Contains parts of the page as PHP file or directory containing PHP files
header.php          Header of site
footer.php          Footer of site
index.php           index of site, now always loads pages/home.php.

The pages directory contains all the body parts of the pages like home.php, about.php etc. It also contains directories like 'portfolio' which in turn contains more .php files.

This is how I'd like my urls to be re-written.

http://domain.com/about         => http://domain.com/index.php?route=about
http://domain.com/about/kittens => http://domain.com/index.php?route=about/kittens

This should however exclude requests directly to the assests or pages folder. The reason why the pages folder should be excludes on direct requests like http://domain.com/pages/about is because some parts of the site are loaded with AJAX. Preferable it would exclude any directory in the root.

Could you guys help me out?

4

1 回答 1

2

You could use an approach along these lines:

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|pages|robots\.txt)
RewriteRule ^(.*)$ /index.php?route=$1 [L]

Save this as .htaccess in your root folder.

于 2013-06-10T10:28:53.720 回答