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

查看:48
本文介绍了.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

.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参数?您可以保证网址始终包含斜杠吗?

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文件夹中,则可以不使用本地主机.

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天全站免登陆