Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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/2/ionic-framework/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/htaccess:如何为任何文件名显示一个内容_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

apache/htaccess:如何为任何文件名显示一个内容

apache/htaccess:如何为任何文件名显示一个内容,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我想将我的表单重定向到不同的地址,例如Thank-a.html、Thank-b.html。。。(能够为谷歌分析设定不同的目标)但页面内容始终是相同的 我的想法是在文件夹和.htaccess文件中有一个index.html页面,在调用任何不存在的文件名时显示index.html。有人能帮我写那封信吗 谢谢大家! 实现这一点的一种方法是只为404使用ErrorDocument: ErrorDocument 404 /yourFolder/index.html mod_rewrite在语义上会更好,

我想将我的表单重定向到不同的地址,例如Thank-a.html、Thank-b.html。。。(能够为谷歌分析设定不同的目标)但页面内容始终是相同的

我的想法是在文件夹和.htaccess文件中有一个index.html页面,在调用任何不存在的文件名时显示index.html。有人能帮我写那封信吗


谢谢大家!

实现这一点的一种方法是只为404使用ErrorDocument:

ErrorDocument 404 /yourFolder/index.html

mod_rewrite在语义上会更好,但不会比这更简单。

首先确保启用了mod_rewrite

在.htaccess文件中放入以下内容:

RewriteEngine On
RewriteRule (.*) index.html [L]

其中index.html是要显示的页面。这与另一个Andrew说的不同,因为在我看来,你想把每个人重定向到一个特定的页面,而不是404页面。如果您想要HTTP状态,重定向到404是可以的,但在这种情况下,我认为作者希望显示实际内容,在这种情况下,请求肯定应该伴随200响应。

您可以在htaccess文件中使用
重写规则。这是一个非常基本的方法,可以重定向任何不存在的路径:

 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /yourfile.html [L]
这几乎就是WordPress的条件


您可以通过检查文件的前缀是否为“thankyou-”或其他内容来进一步修改它。在这里可以找到一个完整的htaccess技巧列表:

这将使“成功”页面成为404页面。在任何情况下都不理想。这就是为什么我不建议这样做的原因。然而,“要求”是为任何不存在的文件显示一个特定的页面。IMO,一个更好的解决方案是至少有一个特定的模式(如Thank-(.*).html)并使用mod_重写,就像其他响应者所建议的那样。