Allow subfolders along with website with .htaccess of Ghost installation - apache

In my Ghost installation on server I want to access a few folders and subfolders, but the main ghost setup's htaccess prevents that. I don't understand htaccess at all. What rewrite rules should be used to allow a few subfolders.
example.nl should be accessible along with all permalinks. Then a particular folder with a few subfolders need to open when path is requested from browser. That's not happening right now. I will need to load index.html files with all css and js etc.
Example: example.nl/subfolder/sub1/index.html
Options +FollowSymLinks -Indexes
IndexIgnore *
DirectoryIndex
<IfModule mod_rewrite.c>
RewriteEngine on
# Simple URL redirect:
RewriteRule ^(.*)$ http://example.nl:62254/$1 [P]
</IfModule>

Related

htaccess - Block access to a directory but allow access to files in a specific directory

In my server I have folder called customers, in which it contains sub-folders [uid] (/customers/[uid]) where uid is the unique identifier assigned to each customer. There are other folders in each /customers/[uid].
Among them there is a folder titled images which, as the name suggests, contains images.
I would like to configure the .htaccess so that the user can only access directly files in the /customers/[uid]/images but the user is not allowed to access any other folder or any directory listing.
Because I am not very familiar with .htaccess syntax, I tried to search some answers online but I am still very confused. Especially giving that I have already a RewriteRule in my .htaccess. I am not sure where and how to add more to accomplish what I want.
This is what my .htaccess look like for now.
DirectoryIndex test.php
<Files "database.ini">
Order Allow,Deny
Deny from all
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
</IfModule>
I am using a VPS hosting, and the directory index is , by default, enabled. So now if I try to access /customers/user it will give me a list of folders where I can continue to access other folders and files
I have tried putting Options -Indexes inside the <IfModule>. After that, I indeed cannot access other directories, but I can't access any files in any directory anymore.
What you an do is make a .htaccess file per every user directory and inside it allow access to ./images
So you will have
/customers/[uid1]/.htaccess
/customers/[uid2]/.htaccess
... etc
and inside every .htaccess you will have:
Allow from all

How To Use Htacess for www.example.com/type.php?user=name

I want to redirect www.example.com/type/name to www.example.com/type.php?user=name
{
RewriteRule ^([a-zA-Z0-9_-]+)/type$ type.php?key=$1
RewriteRule ^([a-zA-Z0-9_-]+)/type/$ type.php?key=$1
}
Please help me about this.
Try adding this to the .htaccess file in your web document root folder (often public_html or htdocs):
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^type/([^/]+)/? type.php?key=$1 [L]
This assumes that mod_rewrite is both installed and activated for .htaccess files. If you are not sure, to check if mod_rewrite is even installed, look at the list of installed modules in the output of phpinfo(); By default, mod_rewrite is not enabled for .htaccess files. If you are managing your own server, open httpd.conf and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All
try this , hope it helps :
RewriteBase /www.example.com
RewriteEngine On
RewriteRule ^type/(.*)/$ /type.php?user=$1
#OR
RewriteRule ^(.*)/(.*)/$ /$1.php?user=$2
PS : The first one works only for the url : www.example.com/type/value ,the second one works for any page in your site ex: www.example.com/anypage/value

.htaccess to block access to files in another directory without <directory>

I'm using the rule below in .htaccess to block bots that hammer my site for the listed .php files, i.e. mydomain.com/join.php:
<FilesMatch "(signup|register|join|timthumb)\.php$">
order allow,deny
deny from all
</FilesMatch>
But how can I also protect the same file names in folders in the tree, i.e. mydomain.com/otherdirectory/join.php?
Those file names in other directories are hit less often than root, but I'd still like throw an forbidden error rather than the site 404 page.
I tried, and since I'm on a shared server, I can't use the <Directory> directive.
You may try this in the .htaccess file in root directory:
Options +FollowSymlinks -MultiViews
RewriteEngine On
# Files to protect in next line
RewriteCond %{REQUEST_URI} (join|file1|file2)\.php [NC]
RewriteRule .+ - [F,NS,L]

Rewrite url rules in .htaccess inside a directory

I'm trying to use rewrite url rules using a .htaccess file. This seems to work fine in my main .htaccess file (only works for php pages which exist in same directory), but when I want to use another .htaccess for php file inside a subdirectory the rules don't apply at all and I get a 404 error page.
The file I want to point to is /news/story.php. story.php requests an integer variable called 'article' to fetch the article from database and display it.
So basically what I want to do is replace http://www.mydomain.com/news/story.php?article=1
with http://www.mydomain.com/news/story/article/1/
I'm using the following rules in the .htaccess file which is inside the 'news' directory.
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine on
RewriteRule story/article/(.*)/ story.php?article=$1
RewriteRule story/article/(.*) story.php?article=$1
Thanks for your help
RewriteRule story/article/(.*)/ news/story.php?article=$1
RewriteRule story/article/(.*) news/story.php?article=$1

Apache redirect directory to index.php

I'm trying to redirect a simple folder to /folder/index.php.
My URL looks like this : site.com/folder and I want site.com/folder/index.php.
Throught de web I only found the reverse way but I do want to see my index.php so that I can later use links like site.com/folder/index.php#344
My .htaccess located in /folder/ looks like this :
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/(.+)$ index.php
</IfModule>
And of course it doesn't work.
Maybe is apache ignoring my file ? Maybe some others .htaccess are interfering ? I have no idea since I'm new to apache...
Thanks for your help
You could just skip this mod_rewrite stuff and use mod_dir:
DirectoryIndex index.php
With that in the htaccess file in /folder, going to http://site.com/folder you will get served the contents of index.php.