我会像这样使用URL的参数 http://localhost/biyahero/user/mark代替此http://localhost/biyahero/user.php?name=mark
我已经尝试了
$test=explode( '/', $_SERVER['REQUEST_URI'] );
echo $test[3];
它工作正常,但是当我访问实际页面时,css和js都无法正常工作。 我错过了什么?
答案 0 :(得分:1)
您必须使用绝对URL来加载css和js文件。
而不是像:
这样的相对网址UPDATE table_name
SET datecol = CASE
WHEN DATENAME(dw, datecol) = 'Monday' THEN 'Minggu'
WHEN DATENAME(dw, datecol) = 'Tuesday'
...
ELSE datecol
END;
使用绝对网址:
../../path/to/cssFile.css
答案 1 :(得分:1)
您需要服务器的PATH_INFO变量才能正常工作。但请注意,您还需要相应地配置服务器。
然后在PHP中,您可以像这样调用pathinfo():
<?php
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');
echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // since PHP 5.2.0
?>
服务器配置 Apache
# Set document root to be "webroot"
DocumentRoot "path/to/webroot"
<Directory "path/to/webroot">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# ...other settings...
</Directory>
和Nginx:
server {
# ...
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =404;
}
# ...
}
警告:如果配置不正确,可能会出现一些安全问题,请确保:
["cgi.fix_pathinfo = 0;" in php.ini][2]