Url not complying to .htaccess rules - .htaccess

I have a problem with one of the url's in my website , it doesn't seem to comply to my .htaccess rules. The problem I'm experiencing is the following.
I access my site using url: http://www.website.com/sitemap
I have the following .htaccess rules:
ReWriteEngine On
php_value include_path ".:/Webserver/blabla/boo"
RewriteCond %{REQUEST_URI} !^/cms[A-Za-z0-9\-_/]*$
ReWriteRule ^([A-Za-z0-9\-_/]*)$ /site/index.php/
ReWriteRule ^$ /site/index.php/
So I would expect this URL call to rewrite to /site/index.php but the point is it never goes there and instead opens sitemap.xml which is in the webroot. It does work for all other URL's in my site. What could be the case here?

I found the culprit. It was due to the MultiViews option set in httpd.conf and each individual site .conf file. I disabled the MultiViews option in the per site .conf file setting it to -MultiViews
Maybe this question fits better in Serverfault. Is there a posibility for me to transfer it?

Related

.htaccess rewrite rule for same words

I have two rules causing problems:
RewriteRule ^posts$ posts.php
RewriteRule ^posts/create$ postscreate.php
I know that I could use "post/create" but these are just two rules out of more that are having all the same problem.
I worked with this rules perfectly on localhost (XAMPP).
However, once I moved the files to my hoster and visited "sub.domain.com/posts/create" it redirects me to posts.php instead of postscreate.php.
Why does it work fine on localhost but not on my hoster? And how can I fix it?
My full .htaccess looks like this (with the two rules only):
AddType application/x-httpd-php .html
RewriteBase /
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://sub.domain.com/$1 [R=301,L]
Options -Indexes
RewriteRule ^posts$ posts.php
RewriteRule ^posts/create$ postscreate.php
The .htaccess on localhost is exactly the same except the https rules. I also tried the .htaccess without the https rules on my hoster but it still didn't work.
Why does it work fine on localhost but not on my hoster? And how can I fix it?
It is most likely due to option MultiViews being turned on on hoster but turned off on localhost.
To disable this use this line on top of .htaccess:
Options -MultiViews
Option MultiViews (see http://httpd.apache.org/docs/2.4/content-negotiation.html) is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So if /file is the URL then Apache will serve /file.html.

.htaccess second RewriteRule note working

I have a PHP page like example.com/new/info.php?title=example. The .htaccess is in folder /new/. I tried it in the main directory also. My .htaccess looks like this:
ErrorDocument 404 /404.php
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ page.php?title=$1 [QSA,L,NC]
RewriteRule ^info/([a-zA-Z0-9_-]+)/$ info.php?title=$1 [QSA,L,NC]
The first Rule is working, but the second sends no GET['title'] to the server. The site info.php loads but without the variable. I have tested it on my localhost and it's working. I load it on my webspace and the second rule is not working.
I tried it also without new directory example.com/info.php?title=example and same not work.
What is my mistake?
It sounds like you have MultiViews enabled (possibly in the server config). You need to disable MultiViews for this to work. Add the following at the top of your .htaccess file:
Options -MultiViews
With MultiViews enabled, mod_negotiation will issue an internal subrequest for info.php when making a request for /info/example/ - before your mod_rewrite rule is processed, so no parameters are passed.

.htaccess block sub domain root but still have access from another domain in a different directory

I hope someone could advise this is a probably is a easy question but my knowledge of .htaccess is limited.
I have inherited a odd file structure that has dependancies on files from a previous install.
Below is a spseudo file structure which mirrors what I have on a sub-domain.
+site-directory
index.html
file.php
another-file.php
+ other-folder
display.php
The sub domain site directory is:
/site-directory
I want to access the sub domain from the main domain from the following url:
/site-directory/other-folder/display.php
the problem I am having is if you put www.subdomainurl.com in the browser the previous install is displayed.
How can I stop this and only access the sub doamin via
/site-directory/other-folder/display.php
I have blocked indexing from robots.txt
What would be best practices for this situation?
Thanks in advance
Question is not very clear to me, so my answer is based on some assumptions.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?subdomainurl\.com$ [NC]
RewriteRule ^$ /other-folder/display.php [R=302,L]

Can we use httpd.conf instead of .htaccess for clean URL?

I have read that setting changes in httpd.conf are much better as compared to making changes in .htaccess as the later one is parsed at Runtime while .conf is parsed at the time of starting Apache. So, is it possible to have all the .htaccess functionality in httpd.conf or there are a few things that have to done in .htaccess only.
Also, can you suggest how to debug clean URL issues?
Basically, I am not able to get the clean URL working. I can access the show.php file but am not able to access the GET variables. Here is the .conf settings.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/show/([^/\.]+)/([^/\.]+) http://www.example.com/show.php?id=$1&img=$2 [L,R]
I have also added
Options Indexes MultiViews FollowSymlinks
AllowOverride All
in <Directory "/var/www/html">
Thanks.
As stated in the Apache manual on .htaccess, anything you can put in an .htaccess file can be put inside a <Directory> block within httpd.conf for better efficiency.
As for your issues with rewriting the URL, your first RewriteCond appears to only be matching URLs that aren't www.example.com (the ! in front is a negation modifier). Remove the ! and see if that fixes the issue. (You probably should remove the second RewriteCond as well, until you have the first one matching; otherwise, debugging problems will be more difficult.)

Remove folder with HTACCESS

When users go to the following url:
http://mysite.com/folder/subfolder?a=blah&b=blah
I need to point them to content that is in the root folder while keeping the variables intact:
http://mysite.com/?a=blah&b=blah
Since http://mysite.com is a virtual host, this solution should also leave other base URLs alone.
I'd prefer not to do a full redirect because we use log tracking in our system and we need to have the headers return a 200 code for the logs (maybe this doesn't matter).
I know that this is a fairly straightforward question for someone who really understands .htaccess redirects. Thanks in advance!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^folder/subfolder/?$ / [L,NC]

Resources