Linux CentOS 7

编程入门 行业动态 更新时间:2024-10-27 12:31:23
本文介绍了Linux CentOS 7-通过.htaccess配置httpd.conf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述
  • 我需要通过 Linux CentOS 7 中的 .htaccess 进行配置,以显示我的 info.php 文件没有扩展名.也就是说,调用 服务器地址/信息,而不是调用 服务器地址/info.php.

  • I need to configure through .htaccess in Linux CentOS 7 that my info.php file is shown without extension. That is, calling server address/info instead of calling server address/info.php.

    此外,在 .htaccess 中,添加 phpinformation 重定向到 info .即, 服务器地址/php信息重定向到 服务器地址/信息.

    Also, in .htaccess, add that phpinformation redirects to info. That is, server address/phpinformation redirects to server address/info.

    我已遵循以下文章.

    在 httpd.conf 文件中,我将 AllowOverride none 更改为 AllowOverride AuthConfig .

    In the httpd.conf file, I have changed AllowOverride none to AllowOverride AuthConfig.

    下一步是什么?

    推荐答案

    要重写文件,您应该覆盖 FileInfo 类型的指令,而不是 AuthConfig 类型的指令(请参见 httpd.apache/docs/2.4/mod/core.html#allowoverride 供参考)

    To rewrite your files you should overrite the FileInfo type of directive, not the AuthConfig ones (see httpd.apache/docs/2.4/mod/core.html#allowoverride for references)

    在apache配置中启用 mod_rewrite 模块并在.htaccess文件中使用类似的配置:

    Enable the mod_rewrite module in the apache configuration and in the .htaccess file use a similar configuration:

    <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^phpinformation$ info.php [L] RewriteRule ^info$ info.php [L] </IfModule>

    更一般的配置:

    <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^phpinformation$ info.php [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ $1.php [L] </IfModule>

    第一个重写规则是相同的,如果您必须使用仅包含phpinformation的url服务请求,请将其重写为info.php并提供该url.L修饰符意味着重写器无需搜索其他重写,而只需请求apache服务即可生成结果(info.php)规则.

    The first rewrite rule is the same, if you have to serve a request with an url containing just phpinformation, rewrite it to info.php and serve that url instead. The L modifier means that the rewriter does not need to search for additional rewriting and can just ask apache to serve the resulting (info.php) rule.

    第二条规则有些不同,重写引擎仅在满足所有先前条件的情况下才执行重写.在这种情况下,原始URL不会解析为现有文件(!-f)或目录(!-d).如果文件/目录存在,将照常提供

    The second rule is a bit different, the rewrite engine perform the rewrite only if ALL the previuous condition are met. In this case the original url does not resolve to an existing file (!-f) or directory (!-d). If the file/directory exists it will be served as usual

    您可能还想执行外部重定向,以强制客户端访问资源的正式URL,在这种情况下,第一个示例可以进行以下更改:

    You may also want to perform an external redirect to force the client to access to an official url for a resource, in this case the first example can change in something similar:

    RedirectMatch ^/phpinformation$ /info <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^info$ info.php [L] </IfModule>

    为什么两个URL都不使用RedirectMatch?原因是客户端用户在浏览器上看到了重定向的URL,因此我们需要删除的.php后缀会再次弹出.

    Why do not use the RedirectMatch for both the urls? The reason is that the client user sees the redirected url on the browser and thus the .php suffix, we need to rid off, would pop up again.

    Mod_rewrite文档 AllowOverride文档 重定向匹配文档

  • 更多推荐

    Linux CentOS 7

    本文发布于:2023-07-16 04:00:42,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1117632.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:Linux   CentOS

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!