我如何配置Apache以将文件名显示为目录?

问题描述 投票:1回答:2

例如,在客户的角度来看,我希望CreateAccount.php显示为http://www.example.com/CreateAccount/。我知道创建很多目录并用index.php填充每个目录很容易,但是我宁愿做最有效的事情。首先,使用该方法将需要高度无组织且不必要复杂的组织标准。其次,我也宁愿充分利用Apache的功能,即mod_rewrite

我知道有mod_rewrite。我已经开始阅读该模块的文档,但是由于我有ADHD,我很快就变得困惑[并感到有点沮丧。我正在阅读。

您能帮我找到最好的方法吗?
apache .htaccess url mod-rewrite
2个回答
1
投票
处理mod_rewrite的最佳方法是创建测试服务器/虚拟主机并缓慢构建配置。另外,请尝试使您的初始规则非常简单,以便您可以准确了解每个规则的作用。此配置可以帮助您开始过程。最后一条规则是您需要将CreateAccount /路径映射到CreateAccount.php脚本。

<IfModule mod_rewrite.c> RewriteEngine On # You can use this only inside of the Directory directive or in the .htaccess file. RewriteBase / # http://www.example.com/page.html to redirect to http://www.example.com/page.php RewriteRule ^(.*).html /$1.php [L] # http://www.example.com/mypath/page.html to redirect to http://www.example.com/mypath/page.php RewriteRule ^mypath/(.*).html /mypath/$1.php [L] # http://www.example.com/CreateAccount/ to redirect to http://www.example.com/CreateAccount.php RewriteRule ^(.*)/ /$1.php [L] </IfModule>


0
投票
或者我什么都没有想到,或者一次至少想到了五件事。当您患有多动症时,您只是盯着随机的事物,而不会思考任何事情,也不会想到脑海中闪现着不同主题的图片和想法。这就是我如此健忘的原因。最终需要花很多时间才能完成我的作业。截止日期可以帮助我激励自己。 Incatalog.kz
© www.soinside.com 2019 - 2024. All rights reserved.