.htaccess mod_rewrite for web service as well as hide other files

筅森魡賤 提交于 2021-02-11 16:06:24

问题


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?

Here is the directory/file structure

/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

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

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

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

to be this:

http://127.0.0.1/xmlrpc/v1/

How does one do this?

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.


回答1:


Ah mod_rewrite. Try this in the xmlrpc directory:

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

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]

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.

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.



来源:https://stackoverflow.com/questions/4566444/htaccess-mod-rewrite-for-web-service-as-well-as-hide-other-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!