Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中使用重写引擎读取文件_Php_Apache_.htaccess - Fatal编程技术网

在PHP中使用重写引擎读取文件

在PHP中使用重写引擎读取文件,php,apache,.htaccess,Php,Apache,.htaccess,最近我正在制作一个php应用程序,我想对我的文件进行一些更改。 所以我使用.htaccess和RewriteEngine,当我想运行我的应用程序时,它说的是404。 这是我的代码,我试着说404 RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^access/(\d+)*$ show.php?address=$1&login=0 例如,这

最近我正在制作一个php应用程序,我想对我的文件进行一些更改。
所以我使用.htaccess和RewriteEngine,当我想运行我的应用程序时,它说的是404。
这是我的代码,我试着说404

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^access/(\d+)*$ show.php?address=$1&login=0
例如,这是我的原始地址:
www.ex.com/show.php?地址=5411496bc2b6c&login=0
我想把它改成:
www.ex.com/access/5411496bc2b6c
以下是我的问题:我在.htaccess中做错了什么吗?

在您的规则中:

RewriteRule ^access/(\d+)*$ show.php?address=$1&login=0
应该是:

RewriteRule ^access/([a-z0-9]+)$ show.php?address=$1&login=0
(\d+)
表示数字,似乎您需要数字+较低的字母字符,对吗

另外,
SCRIPT\u FILENAME
将匹配正在执行的脚本文件名,因此它永远不会是目录,您也将重写真实的现有目录,而是使用
REQUEST\u URI
REQUEST\u FILENAME

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
这对我有用:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^access/([a-z0-9]+)$ show.php?address=$1&login=0 [L]
试试这个规则:

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^access/([^/]+)/?$ show.php?address=$1&login=0 [L,QSA,NC]

哎呀,我不知道(\d+)表示数字,是的,代码是php中的uniqid,我尝试了你的代码,但我仍然有404!试试最后一个,告诉我你可以直接访问
show.php?address…
?或者您是否定义了更多的重写规则?然后使用[L]我已经添加了
L
标志tnxYep,这对我来说是可行的,但是css和javascript没有加载!
/access/
是真正的目录吗?或者你还有其他规则吗?@anubhava不,这不是真的!事实上,我问了两个问题:)@anubhava我不明白,如果你是指其他规则的话。htaccess不,我只有这个是的,这对我来说是可行的,但是css和javascript没有加载!!如果只允许单词字符,请使用
RewriteRule^access/(\w+)/?$show.php?address=$1&login=0[L,QSA,NC]
。对于css/js问题,请在css、js、图像文件中使用绝对路径,而不是相对路径。这意味着您必须确保这些文件的路径以
http://
或斜杠
/
开头。您可以尝试将其添加到页面的HTML标题中:
,以便从该URL而不是当前URL解析每个相对URL。