htaccess not working - .htaccess

I just inherited an ExpressionEngine site from someone without much documentation for how it was put together. I'm trying to set up some 301 redirects, but the htaccess file is being ignored. I have a file named .htaccess in the same directory as our index file, yet it isn't being read.
Our IT department says that AllowOverride in Apache is set to "all," and they suspect that the problem is within ExpressionEngine. Is there a place within ExpressionEngine where htaccess can be enabled/disabled, or is this an Apache thing?
Thanks!

Thanks. Here's what I have in the htaccess file:
# Standard .htaccess file
# Secure .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
Redirect 301 /index.php/info_resources/sites http://www.cptc.edu/index.php/site_directory/
# Don't show any directory without an index file
Options -Indexes
# Dont list files in index pages
IndexIgnore *
# EE 404 page for missing pages
# May differ depending on where your template is located.
ErrorDocument 404 /index.php?/site/404

Related

.htaccess in subdirectory to deny everything in subdirectory except index.php

Here's what the web hosted directory looks like:
public_html
subdirectory
index.php
other stuff
.htaccess
Is there a way to make the .htaccess file deny everything relative to its location (i.e. everything in the subdirectory) except for the index.php file in that directory, without affecting anything located in its parent directory?
I've tried the following, but it's denying me access to /subdirectory/ as well. If I do /subdirectory/index.php it seems to work.
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
<Files ./index.php>
Order Allow,Deny
Allow from all
</Files>
The most ideal is if the solution is agnostic of the directory structure it's in -- that is in the future I could move everything to the parent directory, and it'd still work.
Try this in the mentioned .htaccess location :
RewriteEngine On
RewriteRule !^(index|$) - [F]
That will only allow request to index at this directory and will not affect parent directory.

htaccess <files> directive affecting subdirectories

The directive in htaccess affects subdirectories as well, so:
<files login.php>
order deny,allow
deny from all
Is blocking access to all files named like that regardless of where they are located. Is there a way to make it apply only to the file in the current directory (where .htaccess is located) but not directories below it?
You can use Location instead of Files
<Location "path/folder/file">
Order Allow,Deny
Deny from all
</Location>
You can use mod-rewrite instead of files directive to deny access to a specific file.
RewriteEngine on
RewriteRule ^login\.php$ - [R=403,L]
This will block access to a single URL http://example.com/login.php .
Or you can also use the following one liner mod-alias based blocking:
Redirect 403 /login.php

how to remove automatic adding '?q=' in htaccess when accessing subfolders

I have a folder in the root called 'php', and when I type a url like this in my site:
http://example.com/php
it turns like this:
http://example.com/php/?q=php
but if the folder doesn't exist, it does not add the '?q='. I've tried adding:
Options -Indexes
but still happens. my site uses 'q=' to access different pages and I don't want the users to know that there's folder/s existing if the url adds a '?q='. how can I remove or disable that? I'm still new to htaccess thanks!
Here is my current htaccess:
#
# Apache/PHP/msys settings:
#
# Protect files and directories from prying eyes.
<FilesMatch "\.(inc|profile|functions|pg|module|test|po|api|sh|ini|json|.*sql|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$">
Order allow,deny
</FilesMatch>
# Don't show directory listings for URLs which map to a directory.
Options -Indexes
# Follow symbolic links in this directory.
Options +FollowSymLinks
# Set the default handler.
DirectoryIndex index.php index.html index.htm
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^([^\.]+)/?$ ?q=$1 [L]
</IfModule>
ErrorDocument 403 /example/error404
ErrorDocument 404 /example/error404

Subdomain not working due to Options -Indexes

Subdomain display 403 error due to "Options -Indexes" in .htaccess.
How to denied directory listing while permitting to Subdomain directory to work?
QUICK ANSWER
Define your DirectoryIndex in the httpd.conf
EXAMPLE
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
AFTER THAT
Add an index.php or index.html file on your subdirectory.
The file you are adding must be the file you want to see when you access the subdirectory. The name & extension must match the values defined in the DirectoryIndex directive.

How do I force visitors to use example.com/index.html?

I've been researching about SEO lately and read in some article that if I force all my visitors to use example.com/index.html (using a 301 redirect) and not example.com, risk of tagging my site as duplicate content by search engines would be far less. So how do I do it?
Thank you.
This should work:
RewriteEngine On
RewriteRule ^/?$ index.html [R,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 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

Resources