.htaccess file to nginx configuration file - file

I really need to convert this .htaccess code to nginx configuration. I have never worked with nginx, so I am pretty new to this kind of stuff.
My .htaccess is not that big. If anyone could convert it to a nginx configuration file, it would be great!
<Files file.swf>
ForceType application/x-httpd-php
</Files>
(I have tried to use the converters which have been previously posted, but none of them seemed to work.)
Thanks in advance,
Zoorah.

Assuming "file" in "file.swf" represents a file name, then ...
location ~ file\.swf {
default_type application/x-httpd-php;
}

Related

React.js and folder access denied for user

I don't know if there is any type of post like this one here on StackOverflow but I just wonder how do I make so people who visit my site can't get access to "ip/folder names".
If it for some help I use react.js and I know some people use the .htaccess file but it doesn't work for me or maybe because I do it wrong. I am kind of new of this sort of things.
Error page
I want actually do so if people visit some page/folder or file they come to a page it says "404 page error"
To be able to use .htaccess files depends on how the apache configuration is done on your server. A .htaccess file needs permission to be able to override standard web configurations. If you want to set that up and use them you can try:
sudo vim /etc/apache2/sites-available/default
Then make sure the line AllowOverride has the value All. That means local .htaccees files are allowed to override.
<Directory /var/www/>
...
AllowOverride All
...
</Directory>
Save and restart the service
sudo service apache2 restart
In your .htaccess file you can add following for creating an custom error page
ErrorDocument 404 /my_custom_error_page.html
Here you can read more about writing .htaccess files
https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file
Hope that helped a bit.

Cakephp installation and root directory

I am working through the cakephp installation for production use and I have a problem. I use hostmonster, so this is a shared server using a LAMP stack. The documentation asks you to change the Root Directory as shown:
DocumentRoot /cake_install/app/webroot
To do this, I added the following statements to my .htaccess file:
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /cake_install/app/webroot/$1 [L,R=301]
This resulted in the error below:
Error: The view for AppController::webroot() was not found.
When I navigate to www.example.com I am taken to the proper address, but there are errors. These errors disappear if I add an index.php to either the address or obviously to the rewrite rule.
So, what am I doing wrong here? Is the documentation incorrect in that the rewrite rule should have the additional index.php, should be address work without it, or is there something wrong somewhere else?
Update: The second part of the errors says:
Error: Confirm you have created the file: /home2/cadwolfc/public_html/cake_install/app/View/App/webroot.ctp
The version of cake that I downloaded did not have anything the /app/View folder. When I created the /App/webroot.ctp file it got rid of the errors, but it overrides all other view calls.
If your hosting provider has not enabled mod_rewrite. Then you would need to delete the .htaccess files
/.htaccess
/app/.htaccess
/app/webroot/.htaccess
If I am wrong and there is nothing wrong with mod_rewrite then you should edit your htaccess file and do something like
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
My guess is this is what you're looking for: HostMonster - How to host the Primary Domain from a subfolder (.htaccess)
On most shared hosts, you can't change the document root. Since hostmonster has mod_rewrite there are no special steps for installing cake on hostmonster. There are several ways to install cake - all of them are valid on hostmonster.
Use a development install
The simplest way to set up an application is to use a development install i.e. so the following folder structure exists:
/home2/cadwolfc/public_html/app
/home2/cadwolfc/public_html/lib
/home2/cadwolfc/public_html/plugins
/home2/cadwolfc/public_html/vendors
/home2/cadwolfc/public_html/.htaccess
/home2/cadwolfc/public_html/index.php
Don't edit any of the .htaccess files unless a specific problem is encountered, or a specific requirement needs to be met. This can be achieved very easily with the following commands or equivalent:
cd /home2/cadwolfc
mv public_html old_public
git clone https://github.com/cakephp/cakephp.git public_html
Or symlink the document root
Alternatively put your files anywhere on the server, and just symlink the webroot:
/home2/cadwolfc/anywhere/app
/home2/cadwolfc/anywhere/lib
/home2/cadwolfc/anywhere/plugins
/home2/cadwolfc/anywhere/vendors
/home2/cadwolfc/anywhere/.htaccess
/home2/cadwolfc/anywhere/index.php
/home2/cadwolfc/public_html -> ../anywhere/app/webroot
In this way only the webroot is public and only the webroot .htaccess file is relevant.
Or copy/move the webroot
Alternatively put your files anywhere but move the webroot to the document root. Then update the root constant to point at where the source files are:
// app/webroot/index.php
/**
* The full path to the directory which holds "app", WITHOUT a trailing DS.
*
*/
if (!defined('ROOT')) {
define('ROOT', '/home2/cadwolfc/overhere';
}
What does cake_install mean?
In Cake's documentation, cake_install is explained as follows:
For the purposes of this example, we assume you chose to install CakePHP into /cake_install.
It's just an example. However, it's an example used in the "production install" section, a production install doesn't have all or the application files inside the document root. Setting up a "production install" with the source files inside the document root is not a production install, it's a custom development install (bringing with it custom problems).
Therefore the logical choice is (both of which are usable/secure with mod_rewrite):
Use a standard development install
use an actual production install
But not a hybrid of the two =)

Newbie - what do I need to do with httpd.conf to make CakePHP work correctly?

(Not sure if this belongs here or on webmasters; please move if necessary.)
I'm a total newbie to Cake and not much better with apache; I've done
a lot of PHP but always with a server that's already been set up by
someone else. So I'm going through the basic blog tutorial, and it
says:
A Note On mod_rewrite
Occasionally a new user will run in to mod_rewrite issues, so I'll
mention them marginally here. If the Cake welcome page looks a little
funny (no images or css styles), it probably means mod_rewrite isn't
functioning on your system. Here are some tips to help get you up and
running:
Make sure that an .htaccess override is allowed: in your httpd.conf,
you should have a section that defines a section for each Directory on
your server. Make sure the AllowOverride is set to All for the correct
Directory.
Make sure you are editing the system httpd.conf rather than a user- or
site-specific httpd.conf.
For some reason or another, you might have obtained a copy of CakePHP
without the needed .htaccess files. This sometimes happens because
some operating systems treat files that start with '.' as hidden, and
don't copy them. Make sure your copy of CakePHP is from the downloads
section of the site or our SVN repository.
Make sure you are loading up mod_rewrite correctly! You should see
something like LoadModule rewrite_module libexec/httpd/mod_rewrite.so
and AddModule mod_rewrite.c in your httpd.conf."
I'm using XAMPP on linux. I've found my httpd.conf file in opt/lampp/
etc, but am not sure what I need to do with it. I've searched for
"rewrite", and there's only one line:
LoadModule rewrite_module modules/mod_rewrite.so
There's nothing about AddModule mod_rewrite.c.
Do I just create a Directory section for the directory I've installed
Cake in and set AlllowOverride to All? (I created a separate
subdirectory of my wwwroot and installed in there, since I also have
installs of Joomla and CodeIgniter.) Is there anything else I need to
do? My download of Cake did come with two htaccess-type files
(._.htaccess and .htaccess) - do I need to do anything with them?
Thanks for any help you can provide to this non-server-admin.
EDIT TO ADD virtual host sample:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot /www/docs/dummy-host.example.com
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
Step 1. You should have mod_rewrite enabled, check using <?php phpinfo();
Step 2. Check AllowOverride
// I believe you already did that.
// Make sure you are doing it for the correct webroot!
<Directory />
AlllowOverride to All
</Directory>
Step 3. Check your default .htaccess files are there in directories /mypro, /mypro/app, /mypro/app/webroot.
Step 4. .htaccess may need path fixes depending upon your cake project installation.
e.g. project url http://localhost/mypro/app/webroot/
/mypro/app/webroot/.htacess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ mypro/app/webroot/ [L]
RewriteRule (.*) mypro/app/webroot/$1 [L]
</IfModule>
EDIT
If you are trying to setup it as local domains, Setup local domains (on windows) with WAMP configured
Note: this may be tweaked a little for different kind of installations
Find your hosts file (mine is located at C:\WINDOWS\system32\drivers\etc\hosts)
Insert this to bottom
# save and close this file named hosts
127.0.0.1 mypro.localhost
To test hostname open command prompt and run ping mypro.localhost # If ping is good then move on
Now open your apache config file
httpd.conf and httpd-vhosts.conf (my files are located at)
C:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf
# uncomment line below
Include conf/extra/httpd-vhosts.conf
C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf
# Insert virtual host entries like this, trim dummy entries (if any)
# Changing DocumentRoot
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/mypro/app/webroot"
ServerName mypro.localhost
</VirtualHost>
Save and close files
Create directory C:/wamp/www/mypro (if you haven’t created before)
ModRewrite enables Apache to manipulate request URLs before it handles the request. For example, if you wanted to store your images in /website_images but you wanted to reference them in your HTML as /img/donkey.jpg you could use ModRewrite to change all requests from /img/* to /website_images/*. The way that it handles this is through Regular Expressions, which have entire books written about them.
As far as Apache goes, there are lots of configuration "directives" (aka options or settings). The most crucial to learn about when you're running your own server are going to be the VirtualHost ones. They allow Apache to handle requests to your server's IP address and route them to the correct website based on the hostname (the domain, essentially). You should place any website-specific directives within that website's VirtualHost configuration, including your ModRewrite rules. Note: you can also load additional directives from a .htaccess file in the website's directory, but this is suboptimal (and requires AllowOverride to be set. If you have access to httpd.conf and the related VirtualHost directives, you should use them instead.
It looks like Apache is already configured to load the ModRewrite module, so you don't need to change that. In the VirtualHost directives for your new CakePHP website, you can use the following directives under the <Directory /path/to/your/website> to setup ModRewrite:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
It looks big and scary, but what that does is tells Apache to direct all requests that it can't handle (because the resources don't exist) to index.php. When that happens, CakePHP takes over and routes the request to the appropriate controller and action.
I'm not familiar with how XAMPP is configured, so I can't tell you where those VirtualHost definitions are going to be. Perhaps someone else can chime in here…

htaccess set specific file to download only

I'm working on developing a javascript framework and I don't want anyone to be able to link to the "nightly build" .js file directly on the server.
Based on my research from google, here's what I have in my htaccess:
<FilesMatch /development/flanvas/flanvas.js>
ForceType applicaton/octet-stream
</FilesMatch>
And I've also tried putting a .htaccess file in /development/flanvas/ and adding:
AddType applicaton/octet-stream.js
Neither have worked so far :(
*edit
I suppose if a user really wanted to snag this, they could curl/ajax it. Is it advised to have the .htaccess check the HTTP_REFERER instead? This could potentially get two birds with one line..
Is the root of your server really the DocumentRoot for the website?
i.e. is /development/flanvas/flanvas.js the absolute path to the JS file on your machine?
I would try
<FilesMatch ^(.*)flanvas\.js$>
ForceType applicaton/octet-stream
</FilesMatch>
or
<FilesMatch /path/to/documentroot/development/flanvas/flanvas.js>
ForceType applicaton/octet-stream
</FilesMatch>
Hope this helps
This is the person that asked the question. Apparently I have no idea what account I posted this question under, but once I figure it out I'll come back and checkmark your question is it 100% worked.
Ended up using:
# Force download for flanvas.js
<FilesMatch ^(.*)flanvas\.js$>
ForceType applicaton/octet-stream
</FilesMatch>

How to install cakephp on localhost?

I wanna to know how to install cakephp on localhost?
Please explain me.
I usually make an apache and mysql installation on a linuxbox. I can use windows too, however I do not recommend it ;)
So, I usually make a new entry into the /etc/hosts file to make a sitename available to cakephp.
127.0.0.1 localhost caketest.local
next step to copy all cakephp files into a subdirectory inside /home/myusername/public_html/caketest
app
cake
index.php
plugins
README
vendors
.htaccess
then I set up the site to apache (not neccessary),
<VirtualHost *:80>
DocumentRoot "/home/myusername/public_html/caketest"
ServerName caketest.local
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "/home/myusername/public_html/caketest">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
restart apache. you also need to edit the .htaccess files and place a RewriteBase directive with hte path to the actual directory, e.g.
RewriteBase /~myusername/caketest
create a database, set the db connection in cake config files and that's all.
you can point your browser to http://caketest.local
if you do not want a test site url you can skip hosts, and apache vhost creation, but the url to use should be http:/localhost/~myusername/caketest
another important thing is to enable userdir modul in apache, and also check if using php is enabled in userdirs too.
If you're on windows, get WAMP. Install it, then download CakePHP in C:\wamp\www\. Extract CakePHP in that folder so you have a folder kind of like this: C:\wamp\www\cakephp\. Now you can access the installation by going to localhost/cakephp/.
An old article of mine but still quite relevant:
Installing CakePHP
Assuming you have a *AMP setup (Apache+MySQL+PHP), just copy the files to your htdocs folder. On Ubuntu, it's /var/www, so you would create /var/www/myApp and copy the whole Cake structure into there, ending up with something like:
/var/www/myApp/app/
/var/www/myApp/cake/
/var/www/myApp/vendors/
/var/www/myApp/index.php
/var/www/myApp/.htaccess
Then you can access your app by the url: http://localhost/myApp

Resources