.htaccess mod_rewrite 用于 Web 服务以及隐藏其他文件 [英] .htaccess mod_rewrite for web service as well as hide other files

查看:21
本文介绍了.htaccess mod_rewrite 用于 Web 服务以及隐藏其他文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我知道如何隐藏文件,但是如何使用 mod_rewrite 来只允许在同一目录中调用 Web 服务?

I think I know how to hide the files but how do I use mod_rewrite to allow only the web service to be called in the same directory?

这是目录/文件结构

/var/www/html/xmlrpc/xmlrpc.server.php
/var/www/html/xmlrpc/xmlrpc.client.php
/var/www/html/xmlrpc/xmlrpc.class.php
/var/www/html/xmlrpc/xmlrpc.ini
/var/www/html/xmlrpc/logs

重要提示:/var/www/html/xmlrpc/logs 有 777 权限在你开始指责我之前,我计划将它移到一个非公共目录中并给予正确的权限.但有人问我是否可以用 .htaccess 文件隐藏它.

Important note: /var/www/html/xmlrpc/logs has 777 permission before you start harping on me I plan to move this into a non public directory and give the correct permissions. But I was asked to see if I could hide it with the .htaccess file.

.htaccess

AuthType Basic
AuthName "My hidden files"
AuthBasicProvider file
AuthUserFile /var/www/html/xmlrpc/.pswds
Require valid-user

.pswds

user:5/abcde1abcdE

另外,我是 mod_rewite/mod_alias 的新手,需要这个 URL:

Also I'm a newbie with mod_rewite/mod_alias and need this URL:

http://127.0.0.1/xmlrpc/xmlrpc.server.php

变成这样:

http://127.0.0.1/xmlrpc/v1/

如何做到这一点?

还知道在 Apache 中的虚拟主机设置上,您可以设置日志文件路径/名称,这也可以从 .htaccess 文件中完成吗?

Also on know on the virtual host setup in Apache you can set the log file paths/names, can this be done from the .htaccess file as well?

欢迎举例,因为这对我来说也是一种学习经验.

Examples are welcome as this is a learning experience for me as well.

推荐答案

啊 mod_rewrite.在 xmlrpc 目录中试试这个:

Ah mod_rewrite. Try this in the xmlrpc directory:

RewriteEngine On
RewriteRule ^v1/$ xmlrpc.server.php [L]

有些问题 - xmlrpc.server.php 是否接受任何 get 参数?你能保证 url 总是包含一个斜杠吗?

Some questions though - does xmlrpc.server.php take any get parameters? Can you guarantee that the url will always include a trailing slash?

要强制尾随斜杠以及其他一些东西,试试这个:

To enforce a trailing slash as well as some other stuff, try this:

# Allows direct linking to files
RewriteCond %{REQUEST_FILENAME} !-f

#Checks if the url is missing a slash, if so, evaluate rule below
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://127.0.0.1/$1/ [L,R=301]

最后一条规则必须根据您放置 .htaccess 文件的位置进行调整.如果它位于根目录,那么它将适用于所有较低的目录.如果它在 xmlrpc 文件夹中,那么您可以不使用 localhost.

The last rule will have to be adjusted depending on where you put the .htaccess file. If it's at the root, then it will work for all lower directories. If it's in the xmlrpc folder, then you can leave off the localhost.

还要记住限制对 .htaccess 文件的访问:

Also remember to restrict access to the .htaccess file:

<Files .htaccess>
    order allow,deny
    deny from all
</Files>

其他人将不得不回答其他问题 - 对此并不熟悉.

Someone else will have to answer the other questions - not as familiar with that.

这篇关于.htaccess mod_rewrite 用于 Web 服务以及隐藏其他文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆