htaccess重写规则忽略index.html

发布于 2024-12-20 07:22:19 字数 501 浏览 1 评论 0原文

我正在使用 CodeIgniter 和 .htaccess 重写 URL,但我希望它忽略 index.html

这样我们就可以随时上传 index.html,因为这将是一个临时登陆页面。通过 index.php 上的主站点链接。

这是当前 .htaccess 中的内容,我已将服务器的目录索引设置为 index.html index.php

RewriteEngine on

RewriteCond $1 !^(index\.html|index\.php|js|img|fonts|data|css|uploaded|mobile_devices|audioplayer|emails|robots\.txt|archive_blog)

RewriteRule ^(.*)$ /index.php/$1 [L]

感谢您的帮助

I'm using CodeIgniter and .htaccess to rewrite the URLs but I want it to ignore index.html.

This is so we can upload an index.html at any time as this will be a temporary landing page. With a link through to the main site on the index.php.

This is what is currently in .htaccess and I have set the server's directory index to index.html index.php

RewriteEngine on

RewriteCond $1 !^(index\.html|index\.php|js|img|fonts|data|css|uploaded|mobile_devices|audioplayer|emails|robots\.txt|archive_blog)

RewriteRule ^(.*)$ /index.php/$1 [L]

Thanks for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

枯叶蝶 2024-12-27 07:22:19

看起来您想重写目录中不存在的所有内容。

尝试这个而不是当前的 RewriteCond:

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

that rather looks like you want to rewrite everything that does not really exist in your directory.

try this instead of your current RewriteCond:

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
故人的歌 2024-12-27 07:22:19

您可以通过使用 FilesMatch 指令直接限制对它的访问,而不是使用 RewriteCond 忽略 index.html 文件。 FilesMatch 接受可以根据文件名(例如,index.html)或任何正则表达式进行过滤的正则表达式。

阻止对index.html 文件的访问

<FilesMatch "index\.html$">
    Order allow,deny
</FilesMatch>

这将完全拒绝对index.html 文件的访问。我承认,我不知道这会对搜索引擎抓取产生负面影响。

要了解有关 FilesMatch 指令的更多信息,请参阅 http://httpd.apache.org /docs/current/mod/core.html#filesmatch


至于您当前拥有的列表中的其余目录,您可以锁定所有目录访问,无论名称如何。它会给你更多的未来报道。

Options -Indexes

要了解有关选项指令的更多信息,请参阅 http://httpd.apache.org /docs/current/mod/core.html#options


最后,您的新 .htaccess 文件将如下所示:

# Protect specific files from access
<FilesMatch "index\.html$">
    Order allow,deny
</FilesMatch>

# Hide directory listing for URL's mapping to a directory
Options -Indexes

# Follow all symbolic links in this directory 
Options +FollowSymLinks

# General rewrite rules
<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

Instead of using RewriteCond to ignore the index.html file, you could instead restrict access to it directly through using the FilesMatch directive. FilesMatch accepts a regular expression which could filter based on file name (e.g., index.html) or any regular expression.

Blocking access to the index.html file

<FilesMatch "index\.html$">
    Order allow,deny
</FilesMatch>

That would completely deny access to the index.html file. I will admit, that I do not know the negative effects this would have on search engine crawling.

To read more about the FilesMatch Directive see http://httpd.apache.org/docs/current/mod/core.html#filesmatch


As for the rest of the directories in that list you currently have, you could just lock down all directory access regardless of name. It would give you a little more coverage going forward.

Options -Indexes

To read more about the Options Directive see http://httpd.apache.org/docs/current/mod/core.html#options


In the end your new .htaccess file would look something like this:

# Protect specific files from access
<FilesMatch "index\.html$">
    Order allow,deny
</FilesMatch>

# Hide directory listing for URL's mapping to a directory
Options -Indexes

# Follow all symbolic links in this directory 
Options +FollowSymLinks

# General rewrite rules
<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
柳絮泡泡 2024-12-27 07:22:19

为什么不使用内置的 environment 函数?

您可以创建一个“维护”环境并将基本控制器设置为您想要的任何内容。然后你只需要编辑index.php 文件来指定你想要的环境。

Why don't you use the built in environment function?

You could create a 'maintenance' environment and set the base controller to whatever you want. Then you would just need to edit the index.php file to specify the environment you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文