tags:

views:

33

answers:

1

I have been trying to add a mod_rewrite to a site but its only barely working.

This URL, "http://domain.com/folder/server/subfolder/index.php" should be rewritten to "http://domain.com/folder/subfolder/index.php?platform=server"

This is the last version i'v tried so far.

RewriteEngine On
RewriteCond %{REQUEST_URI} !(css|images|scripts|js|files)
RewriteRule ^([A-Za-z0-9]+).*/(.*)$ $2?platform=$1& [L]

The rule should work for every URL, wether there are no subfolders, just 1 or 5. What i can not do is make the rewriteRule do stuff like index.php/server/argument2/argument3 cause i would have to rewrite all the code to be compatible to this.

Any help would be greatly appreciated.

A: 

Try this rule:

RewriteRule ^([^/]+)/([^/]+)/(.+) $1/$2?platform=$2 [L]

Edit  If you want to use the rule in a subfolder below the document root with an arbitrary number of following path segments, try this rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/(.+) $2?platform=$1 [L,QSA]
Gumbo
I think he only wants a blacklist of directories as well (`(css|images|scripts|js|files)`) that shouldn't be forwarded
Dan Beam
I want to prevent images, css, scripts, etc to pass through this rule.And the RewriteRule above doesn't quite work, it always expects: server/subfolder/file.phpI need it to expect either 0 or more subfolders, so server/file.php or server/subfolder/subfolder/file.php.Cause i have URLs like server/cms/cms.php and server/index.php.
With a minor adjustment the rewrite rule above worked:RewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^([^/]+)/(.*) $2?platform=$1 [L,QSA]