RewriteRule not working after migration - apache

I have an .htaccess file that was on a server:
RewriteEngine on
Options +SymLinksIfOwnerMatch
RewriteRule ^machine/register.* register.php
<Files .htaccess>
order allow,deny
deny from all
</Files>
For requests to the server at /machine/register?id=.... this used to work. I then migrated servers and now its returning a 404.
I enabled RewriteLog and it shows:
(2) init rewrite engine with requested uri /machine/register
(1) pass through /machine/register
I checked the file permission on register.php and it belongs to the same owner as the rest of the files and has permissions 666. What is the problem here?

The problem was that the configuration had the following:
<Directory ...path>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
</Directory>
I changed this to:
<Directory ...path>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
and it worked. Ill leave this here if someone else runs into this issue.

Related

Can FallbackResource support wildcards?

Here is my Directory configuration:
<Directory /var/www/html/sub-dir/*>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
FallbackResource /sub-dir/*/index.php
</Directory>
However, this directive does not seem to work.
Is there a method to accomplish this? Or would it be best to Fallback to a PHP routing script?
Thanks in advance for the help.
Edit:
I have found the <DirectoryMatch> tag and have decided it is probably what I was looking for. However, the syntax evades me. Here is what I have currently:
<DirectoryMatch "^/var/www/html/sub-dir/(?<chindex>[0-9])">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
FallbackResource /subdir/%{env:MATCH_CHINDEX}/index.php
</DirectoryMatch>
My DocumentRoot is /var/www/html
I have two directories:
/var/www/html/sub-dir/0/
/var/www/html/sub-dir/1/
I want this rule to apply to both directories, but using the index.php contained within the respective directories (at /0/index.php and /1/index.php, respectively).
The server currently errs for 400 Bad Request when typing https://domain.tld/sub-dir/0/Extraneous-Text-That-Should-Trigger-FallbackResource
Which part of my syntax is incorrect?
Assuming that /var/www/html is your DocumentRoot, use:
<Directory /var/www/html/sub-dir/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
FallbackResource /sub-dir/index.php
</Directory>
The fallback page /sub-dir/index.php would be used for non-existing paths below /sub-dir/
like /sub-dir/foo.php or /sub-dir/foo/bar.php and you can access the original URL via the PHP $_SERVER['REQUEST_URI'] variable.
For a different fallpage page under a sub-directory of /var/www/html/sub-dir/ like /var/www/html/sub-dir/sub-dir2 you would need another FallbackResource, e.g:
<Directory /var/www/html/sub-dir/sub-dir2/>
FallbackResource /sub-dir/sub-dir2/index.php
</Directory>
or implement a routing/include mechanism in /sub-dir/index.php.

Drupal 7 only works with index.php in url. Want to use friendly clean url

Installed drupal 7 in rhel server. I can able to access the pages with index.php. Without index.php, page is redirecting to 404. My root application folder is var/www/html/sivaraj
sivaraj.com/index.php/profile - works fine
sivaraj.com/profile - getting 404
mode_rewrite is enabled in apache.
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Allow From All
Require All Granted
</Directory>
When change AllowOverride to All gives Internal Server Error 500
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Allow From All
Require All Granted
</Directory>
Didn't change anything in drupal default .htaccess. Tried with RewriteRule to remove index.php nothing worked.
try to change AllowOverride None to AllowOverride All
Also Apache should be restarted afterwards

.htaccess deny from all doesn't work

my problem is that I want to deny the access to a folder but I can't.
I've put a .htaccess file in this folder with just these lines:
order deny,allow
deny from all
Any idea of what can be happening?
I get it! It was due to the apache configuration. In my foo.conf of sites-avaiables directory I had:
AllowOverride None
As apache doc says, AllowOverride Description: Types of directives that are allowed in .htaccess files
When it is changed to:
AllowOverride All
it works perfectly!
You can also configure it with specific options:
AllowOverride directive-type
directive-options at: apache.org
I had the same issue using that method. Try this instead:
RewriteEngine On
RewriteCond %{REQUEST_URI} foldername
RewriteCond %{REMOTE_ADDR} !^111\.222\.333\.44$
RewriteRule . - [R=404,L]
With this method you need to add your own ip.
Options: instead of the last line being a 404 page not found:
RewriteRule . - [R=404,L]
you can change it to a 403 forbidden:
RewriteRule .*? - [F]
or redirect to your homepage:
RewriteRule . http://www.domain.com/ [R,L]
you need to do two things,first, change the conf of apache to allow override,
second, to change the conf of a hosting to allow override
first
nano /etc/apache2/apache2.conf
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
and change it to;
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Second
cd /etc/apache2/sites-available
nano yourdomain.com.conf
add the following codes into it,
<Directory "/var/www/html/yourdomain.com/public_html">
AllowOverride All
Require all granted
</Directory>
after adding
<VirtualHost *:80>
ServerAdmin support#yourdomain.com
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/html/yourdomain.com/public_html/
<Directory "/var/www/html/yourdomain.com/public_html">
AllowOverride All
Require all granted
</Directory>
Use this:
<Directory /folder_name>
Order Deny,Allow
Deny from all
</Directory>
Its better to add a rule to allow your ip address. You can use allow from your_ip_address for this. Be careful with the ip address as it can be shared. You can check your ip address using http://www.whatismyip.com/

404 Error on Certain Pages Using SSL

I'm trying to enable ssl on my wordpress site and am running into a bit of difficulty. I've enabled ssl admin through the wordpress ssl plugin (well reviewed) and also required ssl for a couple other pages. The administration panel works well with https as does the homepage and a couple other pages. However on many of them, namely pages that I've dynamically generated with a php plugin that I wrote, I get a 404 error:
Not Found
The requested URL /create/5 was not found on this server.
Apache/2.2.22 (Ubuntu) Server at upsmart.com Port 443
Approaches that havent worked so far include:
I've enabled mod-rewrite on the server, I've tried changing the site url in the dashboard to explicitly be https:// and I've scanned the php for hard-coded instances of http://
Really scratching my head on this one so any ideas would be appreciated.
For reference I'm using Apache on Ubuntu 12.04.
Update!
I checked my Apache error log and came out with the following message:
File does not exist: /home/user/www/create
My reaction upon seeing that is "Well of course it doesn't. If I'm trying to get it to get it to http://example.com/create/ why would it be reading that as ~/www/create?
Please allow me to blush a little; the update I gave to the question above allowed me to take a guess at the issue but I'll put it down in case anyone else runs into the problem.
I found that I had only half-configured the file /etc/apache2/sites-enabled/default-ssl.
The file began as follows:
ServerAdmin webmaster#localhost
DocumentRoot /home/sam/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/sam/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride none
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
The issue was that the second AllowOverride needed to be changed from none to all. So that it would look like this.
ServerAdmin webmaster#localhost
DocumentRoot /home/sam/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/sam/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride none
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
Mind you: This must be configured for ssl even if you have configured this for other sites-enabled like 000-default.
There's no difference between the configurations.

.htaccess of getsimple gets me a 500 Internal Server Error on Ubuntu Localhost

localhost setup
ubuntu 12.04
mod rewrite enabled
multiple sites running in different directory’s
dir structure
/var/www/mysite1/htdocs/
/var/www/filehostwatch.com/htdocs/
.
.
.
wordpress .htaccess that works in my getsimple dir(copyed for test reasons) without problems
the one from getsimple gives me a 500 The server encountered an internal error or misconfiguration ... i later figured out that this section is what caussing the error
.htacess
AddDefaultCharset UTF-8
now the section that causes errors
Options -Indexes
# blocks direct access to the XML files - they hold all the data!
<Files ~ "\.xml$">
Order allow,deny
Deny from all
Satisfy All
</Files>
<Files sitemap.xml>
Order allow,deny
Allow from all
Satisfy All
</Files>
end of the section that causese 500 errors
RewriteEngine on
# Usually it RewriteBase is just '/', but
# replace it with your subdirectory path
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /?([A-Za-z0-9_-]+)/?$ index.php?id=$1 [QSA,L]
the config file in /etc/apache2/sites-enabled/ of the site looks like the one with another site where wordpress is running without problems. and as i said the htaccess from wordpress works even in this site when copied over.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName filehostwatch.localhost
DocumentRoot /var/www/filehostwatch.com/htdocs
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/filehostwatch.com/htdocs/>
Options Indexes FollowSymLinks MultiViews
AllowOverride FileInfo
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Any idea what might cause this problem?
You should probably change Satisfy All to Satisfy Any in the offending section to see if it helps.
AddDefaultCharset UTF-8
Options All -Indexes
# blocks direct access to the XML files - they hold all the data!
<Files ~ "\.xml$">
Order deny,allow
Deny from all
</Files>
<Files sitemap.xml>
Satisfy Any
Order allow,deny
Allow from all
</Files>
RewriteEngine On
# Usually it RewriteBase is just '/', but
# replace it with your subdirectory path
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /?([A-Za-z0-9_-]+)/?$ index.php?id=$1 [QSA,L]
If I'm understanding your problem correctly... .htaccess is in your /var/www/filehostwatch.com/htdocs/ directory? In which case I don't think you're giving enough permissions for your .htaccess file to configure what you want... In your virtual host settings you have:
<Directory /var/www/filehostwatch.com/htdocs/>
...
AllowOverride FileInfo
...
</Directory>
Which gives the ability to change mod_rewrite settings, but doesn't permit changing of host accesses (e.g. Allow & Deny) nor the changing of Options.
Have you tried setting this to AllowOverride All in your virtual host config? Alternatively you could add more directive settings to the AllowOverride option. Offhand I think AllowOverride FileInfo Limit Options should do the trick.
See also Apache's doc on AllowOverride