tags:

views:

19

answers:

2

Hello... I am struggling to achieve this simple thing...

I have some static pages which should be like
www.domain.com/profile etc.. The problem is how to write the rewrite rules in order to ..

There would be some fixed rewrites like /home

I want every file that exists not to be rewritten www.domain.com/test.php should go to test.php

Lastly if it is not found i want it to be redirected to static.php?_.....

RewriteRule ^/home/?$ /index.php?__i18n_language=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([^/]+)/?$ /static.php?__i18n_language=$1  

This works ok but if i type index.php or test.php or even the mach from other redirection it gets me in static.php... Please help!

+1  A: 

I haven't used this in a long time, but it's something I found, that should help. It is part of an old script that generates .httaccess files for redirecting from /usr/share/doc only when the doc isn't found: The rule is "Check, and if the target url exists, then leave":

RewriteEngine On
RewriteBase /doc/User_Documents

### If the directory already exists, then leave
### We're just redirecting request when the directory exists but has been renamed.

RewriteCond %{REQUEST_FILENAME} User_Documents/([^/]+-[0-9][^/]*)
RewriteCond $PWD/%1 -d
RewriteRule .* - [L]

It's the [L] that means leave if one of the conditions is matched. In the old script, there are hundreds of generated rules (after [L]) that are skipped, because one of the conditions matched. In your case you would skip the rest of the rules when the target %{REQUEST_FILENAME} is found.

So, I suggest, before the redirection rule:

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
Frayser
+1  A: 

According to your description you can use these rules:

# stop rewriting process if request can be mapped onto existing file
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteRule ^ - [L]

# rewrite known paths /home, /foo, /bar, etc.
RewriteRule ^/(home|foo|bar|…)$ /index.php [L]

# rewrite any other path
RewriteRule ^ /static.php [L]
Gumbo
thanks.. the problem is that request_filename didnt return full path! fixed it with adding prefix document root variable
Parhs
@Parhs: Oh yes, that is possible: “The full local filesystem path to the file or script matching the request, if this has already been determined by the server at the time `REQUEST_FILENAME` is referenced. Otherwise, such as when used in virtual host context, the same value as `REQUEST_URI`.” (see [`RewriteCond` directive](http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond))
Gumbo