Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.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/8/.htaccess/5.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 .htaccess url使用变量重写_Php_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Php .htaccess url使用变量重写

Php .htaccess url使用变量重写,php,.htaccess,mod-rewrite,url-rewriting,Php,.htaccess,Mod Rewrite,Url Rewriting,我试图通过使用“重写”更改,使我的URL在网站的特定子目录中看起来更漂亮: www.example.com/sub/file/{some_number}/ 内部至: www.example.com/sub/file.php?var={some_number} 我一直得到404。 我已经使用一个.htaccess文件从我的站点中删除了.php扩展名,该文件如下所示: RewriteEngine on # ## Internally rewrite extensionless file reques

我试图通过使用“重写”更改,使我的URL在网站的特定子目录中看起来更漂亮:
www.example.com/sub/file/{some_number}/
内部至:
www.example.com/sub/file.php?var={some_number}

我一直得到404。 我已经使用一个.htaccess文件从我的站点中删除了.php扩展名,该文件如下所示:

RewriteEngine on
#
## Internally rewrite extensionless file requests to .php files ##
#
# If the requested URI does not contain a period in the final path-part
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
# and if it does not exist as a directory
RewriteCond %{REQUEST_FILENAME} !-d
# and if it does not exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# then add .php to get the actual filename
RewriteRule (.*) /$1.php [L]
#
## Externally redirect clients directly requesting .html page URIs to extensionless URIs
#
# If client request header contains html file extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP
# externally redirect to extensionless URI
RewriteRule ^(.+)\.html$ http://www.dirtycoffee.com/$1 [R=301,L]

# If client request header contains php file extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php\ HTTP
# externally redirect to extensionless URI
RewriteRule ^(.+)\.php$ http://www.dirtycoffee.com/$1 [R=301,L]
我当前的尝试是在顶部添加一行,如:

#Subdirectory rewrite:
RewriteRule ^sub/file/([0-9]+)/?$ sub/file?num=$1 [L] # Handle requests for file
我知道我一定有冲突的规则,但我认为如果应用新规则,[L]就会停止。

而不是:

RewriteRule ^sub/file/([0-9]+)/?$ sub/file?num=$1 [L]
尝试:


您认为
[L]
将停止处理规则是正确的,但这也意味着您无法删除.php扩展名,因为该扩展名的规则低于此扩展名。还要注意前面的斜杠。

就是这样!非常感谢你!我想我已经盯着这个方向看太久了。另外(谷歌的旁注)不得不更新我的css页面的链接,因为页面将其视为目录更改。
RewriteRule ^sub/file/([0-9]+)/?$ /sub/file.php?num=$1 [L]