I basically want to rewrite any request starting with foo/
to foo/index.php?url=
. For example, http://localhost/foo/something
should become http://localhost/foo/index.php?ur开发者_运维问答l=something
.
I currently have this rule:
RewriteRule ^foo/(\w*) foo/index.php?url=$1
This works on my localhost, but not on a free hosting service online. The point is, that it there also rewrites existing files... So my layout has gone, as well as all images etc, because foo/style.css
becomes foo/index.php?url=style.css
. This isn't happening on my localhost.
I came across this similar question: mod_rewrite: Redirect if anything but a file, but it didn't do anything actually.
So how would I go about rewriting anything except existing files here? Why does it only work on my own localhost?
If this does not work:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^foo/(\w*) foo/index.php?url=$1
try this:
RewriteRule ^foo/(\w*)$ foo/index.php?url=$1
with added $
sign. But this doesn't rewrite URLs with non-word chars like a dot (so foo/style.css
wont be rewritten).
Maybe if you add the extension to the regex? That is to say requestion the dot
not to be present?
RewriteRule ^foo/[^.]+ foo/index.php?url=$1
Or I guess you can add the $ to your own
RewriteRule ^foo/(\w*)$ foo/index.php?url=$1
Cause else it can match files since foo/style matches (you did not require next char to be end of URL)
How is it?
精彩评论