问题
I've searched all similar questions and failed:
I wrote a url rewrite similar to the one implemented in zend framework (PHP):
localhost/user/new
Calls for a Controller Named UserController
and executes a function NewAction
. Works like a charm.
But I have some problems with $_GET
, $_POST
and Images and I guess it's because of the htaccess file. It goes like this:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
I use jQuery ui and jQuery UI uses relative links in its CSS.
If I do something like this
http://localhost/login
the images load fine and everything works.
If I add a trailing slash like http://localhost/login/
or http://localhost/login/param1
, the image gets loaded, but the controller gets called, too:
http://localhost/login/param1/images/ui-bg_glass_75_e6e6e6_1x400.png
I don't get how to correct this. There is also a pending problem with post & get via forms, but I guess that this maybe related, so I just want to clear this.
Thanks so much!
回答1:
let me explain:
the RewriteCond %{REQUEST_FILENAME} !-f
checks if you try to load a file that does not really exist on your server, RewriteCond %{REQUEST_FILENAME} !-d
checks if you try to load a directory that does not really exist on your server.
so if you try to load a file that does not exist it is redirected to index.php.
if your url is 'http://localhost/login/param1/images/ui-bg_glass_75_e6e6e6_1x400.png' then there must be an image named ui-bg_glass_75_e6e6e6_1x400.png in a directory calles images which lies in a directory called param1 which lies in a directory called login which lies in your server-root-folder. if there is no such directory structure or image then the request ist send to index.php
if you want to load the image images/ui-bg_glass_75_e6e6e6_1x400.png then dont put the login/param1 before it.
maybe including the jquery-css using an absolute link will solve your problem.
<link href="http://localhost/jquery-ui.css" type="text/css" rel="stylesheet">
then the relative links in the css file will be relative to the path specified in that link-tag.
来源:https://stackoverflow.com/questions/8322997/htaccess-css-images