Can I protect with a .htaccess file some routes with sinatra? - ruby

I wrote a small app with Sinatra and have some admin routes (/admin/new, admin/edit/2, ...) and want to protect them with a .htaccess prompt. Can somebody tell me how I do that?

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /path/to/file/.htpasswd
<Files "protected.html">
Require valid-user
</Files>
If you want to use Sinatra for Authentication, check out this faq.

Related

Magento REST API response getting 404

We configured the REST API user and permissions from magento admin side.
Then we tried the Authorization method with customer key and secret and got the access token and token secret.
Then we tried to call the API URL with OAuth version 1.0
[Magentosite]/api/rest/products
but end with a 404 error.
Also some where i found the url need to be in below format...
[Magentosite]/api.php?type=rest/products
but end with a Invalid webservice adapter specified.
Using magento version - 1.9.0.1
Can someone please suggest what is wrong in this end url calls ?
It worked and got response after we put below changes in apache file
/etc/apache2/sites-available/default
<Directory /var/www/mymagento/>
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
In my case the .htaccess of the production server was missing the following line, I figured out by comparing my localhost and production server's .htacess file.
############################################
## rewrite API2 calls to api.php (by now it is REST only)
RewriteRule ^api/rest api.php?type=rest [QSA,L]
In my case, even having my localhost properly configured, I was still receiving a 404 because in my request header I wasn't sending the content type:
Content-Type:text/xml
After this first succesfull request, I was able to consume the api, and in the next requests, the content-type wasn't necesary,even if I didn't send the proper credentials, magento returns a 503, not a 404 like before.
You already answered to your problem, magento to access REST API, you got 404 url not found mostly link to missing to AllowOverride All in your apache config for the folder like as stated in https://magento.stackexchange.com/questions/29936/rest-api-returns-404
<Directory /var/www/html/magento/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Add your setting in /etc/apache2/apache2.conf
For anyone still getting the 404 after following all other advice, make sure that MultiViews isn't set in the Apache VirtualHost config.

.htaccess i want to deny access to all world but one ip for one page for ajax

here is the .htaccess
<Files login.php>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Files>
ip adress of my server is written in original one where 127.0.0.1 is.But all access denied to login.php ,i have ajax login form so it needs to reach login.php but it cant.please help :(((
Try adding Satisfy any like this:
<Files login.php>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Satisfy any
</Files>

Password form for iPhone (Simple)

I am trying to create a webform on the internet that is mobile. I have everything working but am confused on how to create a single password login form.
Example: You click a link and it will direct you to a password only login. The password does not have to be stored in a database but it is just asking for a password, then when you enter the right one it directs you to a website with the download and if you enter it wrong it will display a popup error saying wrong password.
Any ideas?
There is a simple way with .htaccess and .htpasswd files. I tried it on my website, visit ph3nx.com/test (Login with username: "test" and password: "1234")
It's just a directory on my webspace where i put a index.htm containing "correct" and this two files:
.htaccess
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /var/www/test/.htpasswd
AuthGroupFile /dev/null
<Files index.htm>
require valid-user
</Files>
.htpasswd
test:zYghPID4qWkpI
It's working with iPhone and Computer and is very simple :)
Here you can create these files: tools.dynamicdrive.com/password
I hope this helps you ;)

301 Redirect from subdomain to URL

I'm trying to set up a 301 redirect from a subdomain to a facebook page. I'm using this below and have uploaded it to the root folder on the server. I've also tried to upload this to the subfolder (example.com/blog), but to no avail...
RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog.example.co.uk
RewriteRule ^(.*)$ http://www.facebook.com/example/$1 [R=301,L]
#Deny access to htaccess
Order Allow,Deny
Deny from all
Does anyone have any ideas why this isn't working?
Thanks in advance,
Ash
NOTE:
I've investigated this a little further and forgot to mention that the subdomain is set up on an old version of Drupal. This causes the site to fail when we set up any subdomain.
We can still navigate to the folder that the subdomain uses and the redirect works fine there.
So, the issue seems to be with drupal and subdomains, not the redirect.
Thanks,
Ash
What kind of error are you getting?
This bit of code would deny access to everything, not just .htaccess like it states in the comments...
#Deny access to htaccess
Order Allow,Deny
Deny from all

2 joomla sites in the same webserver

people i have to create a second site in the same webserver that i already have my first site. i,m not sure on how i can do this, i would not like to have to change all the url that i have already created. i was thinking on installing a second joomla inside the folder where is the first one. the url will be www.myweb1.com/joomla2, that is something that i would not like is there a way by my dns that i can change that www.myweb1.com/joomla2, to www.joomla2.com
I just want to create a new joomla site in the same webserver that i already have one joomla site. I,m using apache2 with opensuse. the first site already have a vhost to manage https rewrite conditions.
Any recomendation.
You can use the proxy functionality of Apache HTTPD.
Such configuration might look like:
<VirtualHost *>
ServerName www.joomla2.com
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://www.myweb1.com/joomla2
ProxyPassReverse / http://www.myweb1.com/joomla2
<Location />
Order allow,deny
Allow from all
</Location>
</VirtualHost>

Resources