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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.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
Apache 如何重写子文件夹的规则?_Apache_.htaccess_Url_Mod Rewrite_Url Rewriting - Fatal编程技术网

Apache 如何重写子文件夹的规则?

Apache 如何重写子文件夹的规则?,apache,.htaccess,url,mod-rewrite,url-rewriting,Apache,.htaccess,Url,Mod Rewrite,Url Rewriting,我对htaccess中的简单重写规则有问题 我的想法是这样的: RewriteEngine On RewriteBase / RewriteRule ^(.*)/$ /$1 [L,R=301] RewriteRule ^company$ /company.php?lang=en [QSA] RewriteRule ^company/about$ /article.php?lang=en [QS

我对htaccess中的简单重写规则有问题

我的想法是这样的:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule ^company$                              /company.php?lang=en [QSA]
RewriteRule ^company/about$                        /article.php?lang=en [QSA]
在本地,它是有效的。 但是在网上它不起作用。 如果我转到URL“www….com/company/about”,我会看到company.php页面。。。 你能解释一下我的问题吗? 非常感谢

这样做:

Options -MultiViews
RewriteEngine On
RewriteBase /

## Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/+$
RewriteRule ^ %1 [R=301,NE,L]

RewriteRule ^company$ company.php?lang=en [L,NC,QSA]

RewriteRule ^company/about$ article.php?lang=en [L,QSA,NC]
重要的更改是禁用选项
多视图
。选项
MultiViews
(请参阅)由
Apache的内容协商模块
使用,该模块在
mod_rewrite
之前运行,并使Apache服务器匹配文件扩展名。因此,如果
/file
是URL,那么Apache将提供
/file.php
(如果您的系统中存在)

我还在您的2条规则中添加了
L
(最后一条)和
NC
(忽略大小写)标志