.htaccess从网址中删除文件名

时间:2018-11-03 23:38:33

标签: apache .htaccess url-rewriting

我正试图从我的url:s中删除:"site.php",看起来像 "example.com/custom-foldername/site.php",因此url:s看起来像"example.com/custom-foldername"

当前它根本不起作用。基本上我的网站只是不更改URL。我知道正在读取.htaccess文件,因为如果我在其中写入垃圾代码,它将产生错误500。

这是我当前的.htaccess代码

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options -Indexes
RewriteRule ^site\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site.php [L]
</IfModule>

2 个答案:

答案 0 :(得分:0)

您发布的代码是前控制器模式-它会将对不存在文件的每个请求重写为文档根目录(而非// convertToHtml is a custom function which returns convertFromHTML(html) let htmlTranscript = convertToHtml(paragraphsArray) // important part htmlTranscript.contentBlocks[0] = htmlTranscript.contentBlocks[0].set('type', 'myType') const contentState = ContentState.createFromBlockArray( htmlTranscript.contentBlocks, htmlTranscript.entityMap ) this.setState({ editorState: EditorState.createWithContent(contentState) }) )中的/site.php。 / p>

如果/custom-foldername/site.php文件位于文档根目录中,RewriteRule 模式也不会与^site\.php$这样的请求匹配。 / p>

  

我正在尝试从我的网址中删除/custom-foldername ...

所有您的URL?您的网址中 all 中是否存在.htaccess?因此,site.php是您的前控制器

如果site.php确实是您的前控制人员,请尝试以下类似的方法:

site.php

这会将未映射到物理文件或目录的所有内容重写为site.php

答案 1 :(得分:0)

更新:我刚才解决了这个问题,但忘了更新

所以,如果有人遇到相同的问题,我发现了solution,这是我当前的.htaccess文件

RewriteEngine On
RewriteBase /
Options -Indexes
DirectoryIndex site.php site.html

当用户“询问”文件夹目录(example.com/cats)时,apache将在其中查找“ site.php或site.html”文件。 (example.com/cats/site.php)如果找到其中一个,则会以(example.com/cats)向用户显示。如果找不到任何一个文件,则会显示正常的“ 404 not found错误”

相关问题