Parent htaccess override subfolder htaccess - php

I have a Zend aplication that uses a hatccess and redirects everything to index.php, but now i need to use a password protect folder in one of the subfolder, but when i tried to acess the subfolder keep giving me 404 error.
here the zend htaccess in the public_html folder:
RewriteEngine On
RewriteRule !\.(js|txt|ico|gif|GIF|jpg|JPG|png|PNG|css|swf|pdf|xml|XML|eot|svg|ttf|woff)$ index.php
SetEnv APPLICATION_ENV "production"
here the subfolder htaccess:
RewriteEngine off
AuthType Basic
AuthName "*folder*"
AuthUserFile "/home/*user*/.htpasswds/public_html/*folder*/passwd"
require valid-user
i tried to add RewriteRule ^blog/ - [L]to the public_html folder as i see in:
Overwrite rewrite-rule of htaccess in parent folder
but it didnt work. what is weird is that if i take the password part of the subfolder htaccess, the "rewriteEngine off" work and i got a list of the files in that folder.
Obs: the server is a apache 2.2.25, so rewriteOptions InheritBefore is not a options
Obs2: the folder and user is not like that on the actual htaccess that was just to hide the names.
Obs3: im a noob in server configurations :)

This usually works for me. Paste code in the parent htacesss underneath your RewriteRule
RewriteRule ^(blog)($|/) - [PT,L]

Related

Remove public from URL Laravel 5.3

I'm using Laravel 5.3 is there a easy way to remove public from URL? is it necessary to add a htacces. when I change the htacces it is getting a n error like below,
copy both htaccess and index.php file from public folder to root directory and then change root index.php code as below
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
After installing Laravel, you should configure your web server's document / web root to be the public directory. The index.php in this directory serves as the front controller for all HTTP requests entering your application.
https://laravel.com/docs/5.3/installation#configuration
Do not edit .htaccess or Laravel related files, just point web server to a public directory instead of Laravel project directory:
DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">
Then restart Apache.
Add a .htaccess file in root which contains -
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
Yes it is very simple no need to add extra htaccess,
Create a new folder in your laravel project folder.
Name it whatever you like. Example :- source
Move all the files from root into 'source' folder except 'public' folder.
4 . Move all the files from public folder to root.
5 . Change the autoload.php path
6 . Thats all. remove public folder if necessary.
In the root directory create a .htaccess file and put the following in
it
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Even above solution(s) work(s) for you,but I would recommend not to do this.
Here is the reason why.
-You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH.
-you have to configure apache for user not access .env, git files , config folder's file
public directory is there for reason to make project a bit more secure. Solve the actual problem and don't try to break this simple but nice security addition.
Copy all files and folder from public folder to root folder and edit your .htaccess file as
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
And dont forget to change the paths in index.php file.
For details refere following links
Installing Laravel in a subfolder
https://ellislab.com/forums/archive/viewthread/151342/#734511

Having multiple htaccess in a root directory

I have directory in my website where user can upload projects or create sub directories, in the root dir i have a default .htaccess file and default.php which i don't want the user to get access to because i rewrite the dir to load default.php as default index page and also this to file will be copied to any sub dir that the user create.
Now my problem is when user try to save .htaccess for the project he want to save it will show that is already exist. is there anything i can do to have multiple htaccess or write my own as default htaccess.
Second. is it possible to use one htaccess in all the sub dir so user can freely add their own?
Example: bellow is how my directory look
WWW.example.com/ project /userprojectname/sub1/sub2/sub3/etc...
In project it has htaccess and users are not allow to do anything but their projectname will save there.
In userprojectname it has an htaccess and default.php, they can also add more file or create directories and any sub dir will also have it own htaccess and default.php.
Now can i make htaccess in project work in all page? and as for default, i used jquery to disallow users creating file name default.php also is there a better way i can fix all this?
Bellow is my dirs and htacess file
Options +FollowSymlinks
RewriteEngine on
#This will block from accessing root folder
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9]+)$ $1.php [NC,L]
DirectoryIndex default.php

Protecting folders with .htaccess

I met some trouble with my website (www.barbarian-strongman28.fr).
I set some url rewriting using this .htaccess which is in the main public folder of my server (called www)
.htaccess:
Options +FollowSymlinks
RewriteEngine On
ErrorDocument 404 /index.php?p=404
# Pages with the PHP p= parameter
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?p=$1&id=$2 [L]
RewriteRule ^([^/]*)\.html$ /index.php?p=$1 [L]
I have a folder called admin that I want to protect.
So I set this .htaccess
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /htdocs/admin/.htpasswd
AuthGroupFile /dev/null
require valid-user
I've uploaded this file in the folder that I want to protect
The trouble I have is that the website also require an authentification even if I am not in the directory protected.
Any kind of help will be much appreciated.
I'm guessing your .htaccess file is in the main directory of your server. That's your problem:
"Also note that if you place this htaccess file in your root directory, it will password protect your entire site, which probably isn't your exact goal."
(from http://www.javascriptkit.com/howto/htaccess3.shtml)
So the solution is simple: put the .htaccess file in the directory you want to protect. You should also make sure of a few things (though they seem ok in your script):
That the paths to all the files are server paths not URLs (you've done this);
That the .htpasswd file is in a secure location
That the .htpasswd file is in the format username:password, with the password encoded - here's a tool for creating .htpasswd files if you need it.
Hope this helps.

Placeholder page while live Magento site is being worked on

I'm converting a site from an ASP shopping cart to Magento. I had to switch hosts to a php server. A lot of the configurations I'm testing require that I have the site hosted on the domain (SSL, module keys, etc).
I set up the new host, have everything set up database and magento wise. But I wanted to know if there was a way to have a landing page on the root while working on magento site on the live url. so if you go to example.com it takes you to the landing page (index.html) but I can bypass this by going to example.com/index.php.
I could put this on a subdomain but that is not ideal since I don't have an SSL cert on subdomains and some of the modules won't be activated on there as well.
Any help would be greatly appreciated as it is up right now and don't want users to see the beta site.
Thanks
just make a file int the root folder and call it "maintenance.flag" magento is redirecting to the "Underconstruction"-File automatically. You might want to style that file though since the default is rather ugly
I used this .htaccess file so that only I could access the page.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^xxx\.xxx\.xxx\.xxx
RewriteCond %{REQUEST_URI} !/index.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /index.html [R=302,L]
</IfModule>
(replace the "x"s with your IP address)
This redirects everything to index.html, unless it's from your IP address.
If you go for the sub-directory version, just work with .htaccess to authenticate access:
http://www.htaccesstools.com/htpasswd-generator/
Otherwise, in the root folder, you may do the following
.htaccess:
DirectoryIndex index.html
AuthType Basic
AuthName "My Protected Area"
AuthUserFile .htpasswd
Require valid-user
<FilesMatch "index.html">
Allow from all
Satisfy any
</FilesMatch>

Remove directory from url htaccess apache

I have website where all the files were in the public_html root so my urls were http://foo.com/index.php
I have moved all my files into a bar directory so now the url is: http://foo.com/bar/index.php however I would like to rewrite the URLs so that the the directory bar is not shown in the urls and the site still appears as http://foo.com/index.php. What is the best way of achieving this? I have LAMP hosting and can change htaccess files.
Thanks in advance.
Put this code in your .htaccess under public_html:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^((?!bar/).*)$ bar/$1 [NC,L]
Then you can access your website as http://foo.com/index.php

Categories