Apache htaccess on Win2k is not being processed - apache

I am trying to rewrite URLs using mod_rewrite. It is enabled in httpd.conf and url rewriting works if the lines are in the httpd.conf file. However, I would like the rules to be in the .htaccess file.
It doesn't appear that .htaccess is being processed at all by Apache on Win2k.
I have ReWriteLogging turned all the way up, but the log file isn't being created. The last line in httpd.conf is
AccessFileName .htaccess
.htaccess contents
RewriteEngine on
RewriteLog "c:/rewrite.log"
RewriteLogLevel 15
RewriteRule /alice.html$ /bob.html
Thanks
edit : Apache version 2.2 on Windows 2k

Check that AllowOverride FileInfo is enabled in httpd.conf for the directories affected; see also http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride. You might also check permissions on the .htaccess files themselves, to ensure there's nothing preventing Apache from reading them.

Related

.htaccess redirect works for .html but not .php using RewriteRule

I want to restrict access to a directory and all of its' sub-dirs and file using the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)ht-test(.*)$ - [NC,R=401,L]
</IfModule>
It works fine on index.html but not test.php. I have not clue what's going on. Shouldn't ^(.*)ht-test(.*)$ match anything containing it in the URL? Tested it with this site and it seems to be mathing both php and html.
I also tried using <Directory "./ht-test"> Deny from All </Directory> but that gives me Internal Server Error no matter what I put in.
Here're my tests:
http://deepcorelabs.com/ht-test/index.html
http://deepcorelabs.com/ht-test/test.php
Finally, figured it out. There's a settings in Plesk for how PHP is served (under Hosting Settings for the domain)
I was using FPM application served by nginx which igonores .htaccess directives for PHP files.
Apparently, for performance reasons
After changing it to 'served by Apache' it worked as expected.
For some reason I thought disabling nginx proxy mode will disable it completely as service.

Apache .htaccess URL rewrite adding additional directory in URL path

I'm trying to build a URL rewrite by adding an additional directory in the URL path; for example, changing;
https://FQDN/mypage/ to https://FQDN/dev/mypage/
https://FQDN/template/ to https://FQDN/dev/template/
I have written the following .htaccess although this is having no affect. I have already enabled a2enmod rewrite.
RewriteEngine on
RewriteRule ^dev/(.+)$ /$1
Thank you #anubhava - simple fix, the rewrite was not activating due to AllowOverride None being active in the apache2.conf file. Changing this to AllowOverride All allowed the .htaccess file to be active.

Redirect access to .htaccess to another file

I was playing around with .htaccess files and I was wondering, completely out of curiosity, is it possible to redirect access to the .htaccess file itself to another file?
Example:
User goes to http://www.example.com/.htaccess
I want the user to be redirected to index.php?foo=bar
I've tried the following:
Redirect 301 /.htaccess /index.php?foo=bar
And
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^((?s).*)$ index.php?foo=bar [QSA,L]
</IfModule>
These methods work on any other file, but the .htaccess file itself always results in a 403 Forbidden page showing up.
Is this possible? If not, then why?
If you look in your webservers configuration file you will find some directive that prevents users from accessing .htaccess or .htpasswd file from the browser. For instance if I open up my apache configuration, located at /etc/apache2/apache.conf I can spot the following lines:
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
So you should be able to change the above to:
Order allow,deny
Allow from all
you also need to make sure that you have the correct file permission on the .htaccess file and finally restart your server using:
sudo service apache2 restart
Of course doing the above would not be very secure.

How to enable apache rewrites step by step

I am writing scripts for Apache URL redirects.
I have researched the rewrite rules to be written.
Now I would like to know the procedure for implementing this.
Enabling mod_rewrites in http.conf
LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c
I have created .htaccess
Now I am not sure of the following.
1.Access rights required to do this.
2.The location to put .htaccess file
3.how to enable logs and write logs.
4.I have two web servers.Do I have to put this in both of them.
My rewrite rule looks some thing like this.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} old_domain\.com [NC]
RewriteRule ^(.*)$ http://www.new_domain.com/test$1 [L,R=301]
It would be good if some one help me with the step by step procedure to perform this.
1.Access rights required to do this.
You need write access to the folder the htaccess file is going to be uploaded to, and the htaccess file itself must have read rights by the webserver (most likely, the "apache" user)
Additionally, you need to have at the very least:
AllowOverride FileInfo
in the server config for the document root directory
2.The location to put .htaccess file
Based on the rules you have, you want it in the document root. It's denoted in the server config by the DocumentRoot directive
3.how to enable logs and write logs.
See: http://httpd.apache.org/docs/current/mod/mod_log_config.html
Specifically the TransferLog and ErrorLog directives
4.I have two web servers.Do I have to put this in both of them.
Do the same thing for each. If both webservers use the same document root, then obviously you don't need to put the htaccess file in 2 places. If they have different document roots, then put the htaccess file in both document roots.

Do I need to change anything in php.ini to make changes to .htaccess?

I am trying to put a rewrite rule on .htaccess, but it's not working. Do I need to make a change to php.ini to enable rules to be added to .htaccess?
Thanks in advance,
John
No, php.ini is specifically related to PHP, .htaccess is Apache.
What are your rules?
If it is something like mod_rewrite, then you may need to enable the mod_rewrite module in Apache.
You have to edit your apache vhost file and allow the .htaccess file to override the settings. This is done by the
AllowOverride
statement in the directory part of the vhost file. And maybe enabling the mod_rewrite.
No, .htacces is completely independent of PHP. It is a apache configuration file to modify the configuration for the folder of the .htaccess file.
To enable Rewriting in your .htaccess
RewriteEngine On
To do so you need to enable mod_rewrite in your apache configuration.
UPDATE:
You don't need the above Code in the .htaccess file if you have the following somewhere in your apache config:
<IfModule mod_rewrite.c>
RewriteEngine on
</IfModule>