.htaccess Rewrite and subdirectories not working - apache

I have this as my .htaccess file:
AddType text/x-component .htc
ErrorDocument 404 /index.php
RewriteEngine on
RewriteRule ^maps/(\w+)/?$ /maps.php?lang=$1 [L]
RewriteRule ^(\w+)/?$ /index.php?lang=$1 [L]
The second RewriteRule is working PERFECTLY! No problems. But, the first one, is giving me a huge headache... It just doesn't work at all. It's redirecting to /maps.php, but it doesn't gives me the parameter, which is BASIC for me. It's like the GET params are not there, but are supposed to be there. I don't get it...because I've just copied a working RewriteRule, from StackOverflow, and addapted changing the word "search" to the word "maps".
Could anybody, please, help me with this thing? I'm pretty sure it'd be something simple, but I'm not seeing it...
EDIT: Apparently, there is a second .htaccess file in my server. "/logs/.htaccess".
Options +Indexes
RemoveHandler .html
RemoveType .html
AddType text/html .html
Satisfy any
Order Deny,Allow
Allow from MY_SERVER_IP
Deny from all
AuthType Basic
AuthName "Access to /logs"
There is no way I can delete this file. Or I didn't manage to do it. My hosting provider is 1&1.

I've found the problem through some deep searching after I realized it could be a problem with my hosting provider, 1and1. And I got it here 1and1 mod_rewrite issues
It was about an option you MUST add in your .htacces file which is:
Options -MultiViews
Now is working more than fine! Thanks to #kjetilh for the support.

Related

Apache URL rewrite change file extension from .htm to .cfm

First let me apologize if this has been asked/answered before. I did a search and could not find what I was looking for. Some questions were close but just not enough. Again apologies for duplication.
Second, my work has always been with IIS and as such my apache knowledge is limited so again, my apologies for asking for a little extra "hand holding" as I learn how to address this issue. Much thanks to any and all for your help.
Now for my question...
I have http://www.mycompany.com/internalUser/[className]/beginClass.htm where [className] is dynamic, for example French101 or Biology210 but each always have beginClass.htm
What I need to do is have a URL rewrite that changes beginClass.htm to beginClass.cfm
What I am not sure of is where should this rewrite code go - in the httpd.conf or .htaccess file within /internalUser folder.
Furthermore, I have tried the following example adding it to the directory tag created for internalUser
-- Copied from httpd.conf
Alias /internalUser "c:/iUser/training"
<Directory "c:/iUser/training">
RewriteEngine on
RewriteBase "/iUser/training"
RewriteCond "$1.cfm" -f
RewriteCond "$1.htm" !-f
RewriteRule "^(.*).htm$" "$1.cfm"
</Directory>
Also created in .htaccess file and neither is working. When I attempt to open the .htm it does not redirect or open the .cfm version. The .htm file is still being opened.
Thanks in advance for any and all help.
Use below for rewrite,
RewriteEngine On
RewriteRule ^internalUser/([^\/]+)/beginClass.cfm$ internalUser/$1/beginClass.htm [L]

Rewrite Rule is not working well

I am investigating Rewrite Rule of Apache and not using .htaccess but virtual host setting for writing them.
Here I have 2 questions:
I can use "RewriteRule blog_rss.xml blog_rss.php" but cannot use "RewriteRule ^blog_rss.xml$ blog_rss.php", why?
Even the first script is working, it doesn't change to the RSS style what I want. Should I set handler for it with Rewrite Rule?
Thanks for answering this question.
Update: Here is the scripts about rewrite rule.
<Directory />
<IfModule mod_rewrite.c>
RewriteEngine On
ErrorDocument 404 /error/404.php
RewriteRule ^blog_rss\.xml$ blog_rss.php
</IfModule>
</Directory>
No you shouldn't set a handler. Doing so will force the PHP code at blog_rss.php to execute as XML. This would result in the entire file being responded with an XML Mime type, which may present major security issues.
However, in the blog_rss.php file before completing the response you might want to set the response type to that of an RSS file.
blog_rss.php
header('Content-Type: text/xml');
v-host
<Directory />
<IfModule mod_rewrite.c>
RewriteEngine On
ErrorDocument 404 /error/404.php
RewriteRule ^blog_rss\.xml$ blog_rss.php
</IfModule>
</Directory>
Resource: electrictoolbox.com
Thanks for answers. For V-host, I found the reason finally.
According to RewriteRule in htaccess vs httpd.conf, the Directory path should be the same as the website base path. For example, if the root directory is /var/www/, the <Directory> should set /var/www/ or it will detect the root path of the server.

Enabling .htaccess for 302 redirects

I am attempting to create an .htaccess file on an Apache server to implement 302 redirects. Hosting is provided by BlueHost.
Right now I am testing an .htaccess file which consists of just a single line:
Redirect http://mydomain.com/?_escaped_fragment_=about http://mydomain.com/about.html
The file doesn't work. After learning more, I created an httpd.conf file, which looks like this:
<Directory />
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
One of the answers to this question (Apache 302 Redirect) suggests the following may be at issue:
mod_alias is not loaded--how do I check whether it is or isn't?
Adding the httpd.conf file may require an Apache restart. Is this possible on a shared BlueHost server?
Any advice on getting the 302 redirects to work is much appreciated. Thank you!
You can't match against the query string in a redirect, you'll need to use mod_rewrite:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=about$
RewriteRule ^$ /about.html [L,R=302]

Magento media url - get rid of 403 Forbidden

on my Magento site (not the real url ;) ), I have http://magento.local.com/media/ returning as a 403 Forbidden.
This seems to be standard for all Magento installs, but I want to change this, and not have a 403 returned for requests to /media/.
How can I do this?
EDIT: (adding further information and reason for it)
I want /media/ to not be a 403, so that I can redirect requests to /media/ to /media/index.html.
I thought this redirect would be easy once the 403 was resolved, but unfortunately it is not. e.g.
RewriteRule ^$ /index.html [L,NC,R=301]
does not redirect /media/ at all, and the usual "Index of /" is displayed.
SOLUTION: add DirectoryIndex to the htaccess file
Thanks
Paul
Put .htaccess to your media/ dir with following contents:
Options All +Indexes
DirectoryIndex index.html
Something to pay attention to.
The standard Magento .htaccess for the media directory is as follows:
Options All -Indexes
<IfModule mod_php5.c>
php_flag engine 0
</IfModule>
# AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI
Due to the relaxed permissions Magento expects on this directory tree, they wish to prevent execution and interpretation of php and other scripts that could be maliciously uploaded into the directory tree and then executed remotely. As long as this function is preserved, you will be ok on modifications you make.

.Htaccess - Server error

I'm getting the following error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.
If you think this is a server error, please contact the webmaster.
Error 500
184.82.228.38
Mon Jan 9 02:48:12 2012
Apache/2.2.21 (Unix) DAV/2 mod_ssl/2.2.21 OpenSSL/1.0.0c PHP/5.3.8 mod_apreq2-20090110/2.7.1 mod_perl/2.0.5 Perl/v5.10.1
Im running a XAMPP server
here is my htaccess file, i don't understand what the problem is.
AuthType Basic
AuthName "Members Area"
AuthUserFile /opt/lampp/htdocs/.htpasswd
Require valid-user
<FilesMatch "(async-upload\.php|wp-cron\.php|xmlrpc\.php)$">
Satisfy Any
Order allow,deny
Allow from all
Deny from none
</FilesMatch>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /members/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /members/index.php [L]
</IfModule>
# END WordPress
I got the same error before and the problem is the location path of the .htpasswd. Make sure you have set the correct path for that file.
I got the same error. It was due to incorrect path of .htpassswd file.
To know current directory path you can use following
echo dirname(__FILE__);
Try to copy your .htaccess and other files to some Internet webhosting and see, if the problem exists there. If not, then you'll be sure that this is purely XAMPP problem. I heard many times that it works really purely about .htaccess run locally.
For example, I don't have working autorization using .htaccess locally, because right after I provide correct login and password I see exactly the same error message as you mentioned. As for me, I'm more than sure that this problem is purely related to incorrect interpretation of .htaccess done by XAMPP (as everything works like a charm on production server), not by some mistakes in .htaccess contents.
I wasted (too) many hours on finding solution and left it. For right now, if I'm developing locally, I rename ".htaccess" to "htaccess", so it is ignored by XAMPP (Apache on-board of it) and re-enable it only when deploing files to production server. This approach maybe isn't to professional, but it saved me a lot of time and stress! :]
On the other hand, if your hosting also fail with the same symptoms, then you'll know, that this is not XAMPP releated problem and you have something wrong with your syntax.
Take a look here for a similar problem reported on StackOverflow.com, where (as I think) the cause is the same as in your issue.
Make sure that your script have the shebang line has the correct path.
Like,
Xamppinstalleddrive:\xampp\perl\bin\perl.exe
I know that this post is old as a mole, but it helped me find my answer still. So I thought, that I would share my solution anyhow.
My problem was, that I had a .htaccess-file in the htdocs-folder. When I moved/renamed it, then it worked.
My .htaccess-file looked like this:
Header add "disablevcache" "true"
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{HTTP_HOST} !^www.COMPANYNAME.dk$ [NC]
RewriteRule ^(.*)$ http://www.COMPANYNAME.dk/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /404.php [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.COMPANYNAME.dk/$1 [R=301,L]
ErrorDocument 404 /404.php
ExpiresActive On
ExpiresDefault "access plus 7200 seconds"
Header unset ETag
FileETag None
<ifmodule mod_deflate.c>
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
</ifmodule>
Delete the .htaccess file and let wordpress create a new one for you[This is if you are running a wordpress site].
Things will be up and running.I had the same issue and got it sorted
I know this is old but this worked for me. How to use htpasswd to create protected directories XAMPP / apache
Essentially, you need to put the OS dir of the htpasswrd file (which is outside htdocs for security reasons). Apache can read your file system, you just have to tell it where the file is.
Disabling htaccess solved the problem for me just now. (Thanks community.) However, rather than subtly deleting the ".", I changed the file name to ".htaccess.disabled".
It achieves the same thing, but it's much easier to spot if I forget to re-enable it later. (I think all of us here can think of a time when hours were wasted because of a missing punctuation mark.)
I solved after just disabling a module:
sudo a2enmod -d deflate
Killing apache and restarting the apache service.
Maybe disabling recent enabled modules solve your problem.