.htaccess directory exemption - apache

I have an Oxwall site in my root directory. It's preventing my subdomain from redirecting to a subdirectory. The directory is a DokuWiki. I am absolutely horrible with RegEx, fyi.
I tried adding a line to my .htaccess, but to no avail
RewriteRule ^modpod/ -
That failed to provide any change. The address [domain]/modpod/ was still handled with the rest of the .htaccess. If I attempt to use the subdomain, I get a 500 error.
Help?

Upon redoubling my search of SOF, and applying a little creativity to an unanswered question, I ended up with a solution.
RewriteCond %{REQUEST_URI} !modpod/.* [NC]
That was added to the beginning of all my Rewrite conditionals. Works perfectly.

Related

How do I rewrite a messy URL as a clean URL using HTACCESS?

I'm trying to turn all pages into clean URLs (so that site.com/new/index.php?page=hello turns in to site.com/new/hello). After doing research, it seems making an HTACCESS file handle path rewriting is the best approach. I've researched this for months and have not yet found a reliable solution.
I've tried a bunch of ways to do this and none are responding. I've even tried it on different Apache servers to see if there was some issue. I've contacted the hosts and it appears all settings are fine.
I've tried a few approaches and variations thereof. I've also tried changing my permissions, changing my settings in cPanel and WHM, and also placing the HTACCESS file in different directories. Nothing has been able to change the URL, though other commands in my HTACCESS file are running, so I know the file is being read.
Here's code I've tried so far:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^page/(\d+)*$ ./index.php?page=$1
And this:
RewriteEngine On
RewriteRule ^([a-z]+)\/([0-9]+)\/?$ index.php?page=$1 [NC]
It appears not to work, as the URL remains the same regardless of whether I've added this script or not.
The site seems completely unaffected by the addition of this code. The HTACCESS file is entirely clean, and there are no other HTACCESS files on the "partition" which would affect it. To replicate, try using the above code in an HTACCESS file in any directory.
I would expect the code to rewrite the URL to a clean format, as it seems most sites recommend code like this to change the URL the way I need. However my site preserves the URL with the page=hello variable as if no HTACCESS script is present.
Any assistance would be much appreciated!

apache rewritemap using txt file - match fail

I am trying to establish a rewritemap using a simple txt file for a special project that will ultimately contain about 150 redirects.
I've read through the other posts here and tried to apply alternate mods, but I just can't make a single redirect from this actually work as expected :-/
To confirm my setup:
I am using an include .conf to update my httpd.conf for the proper Virtual host. Upon running /scripts/rebuildhttpdconf (and 'service httpd restart') it is applied without error and the appropriate Include Path reference within httpd.conf becomes uncommented, which tells me it is finding the include file as expected. The Include file is called 'redirecttest2.conf' and contains:
RewriteMap redirect2 txt:/home/example/public_html/redirecttest/redirect2.txt
At the location referenced above, I have the file 'redirect2.txt', which for testing purposes contains:
maintenance.html http://www.example.com/maintenance2.html
maintenance1.html http://www.example.com/maintenance2.html
So my expectation would be that when entering 'example.com/maintenance.html' it would then be redirected to maintenance2.html, etc.
In the .htaccess file at the root of the effected domain, I currently have the following:
RewriteEngine on
RewriteCond %{REQUEST_URI} !(\.(js|css|less|png|php|swf|flv|jpg))$
RewriteCond {redirect2:$1} !=""
RewriteRule ^/(.*) ${redirect2:$1} [R=301,L]
However, this does not currently have any effect. Entering example.com/maintenance.html or maintenance1.html does not perform any redirection - with or without the first two conditionals commented out.
I have tried numerous variations, and at times been able to break it altogether (rewrite loop error, whitescreen, or even cases in which the redirect works but instead of going to maintenance2.html, it appends /home/example/public_html to the url - ???) - but at no point can I get the example above to redirect as expected.
I tried getting assistance from the host of the VPS, but they do not provide support for such modifications.
I am hoping someone could look at the above and maybe see something glaring that I am missing? ANY thoughts appreciate...
I was finally able to resolve the issues with my RewriteMap.
In the .htaccess file at the root of the impacted domain, I am now using the following:
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.(js|css|less|png|php|swf|flv|jpg))$
RewriteCond ${redirect2:$1} >"" [NC]
RewriteRule ^(.*) ${redirect2:$1} [R=301,L]
This now appears to work - at least for basic url's.

multiple domains with htaccess rewrite rule

I'm having difficulties getting an htaccess to work with a subdomain.
my server structure:
root / index.php ---//codeigniter index file, for application A, main domain points here.
root/staging/StagingWebsite ---// my subdomain is pointing here.
the folder StagingWebsite has a file called temp.html
moving on, my root htaccess file is this :
RewriteEngine on
RewriteCond
RewriteCond $1 ^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Which turns any access to MyDomain/foo to MyDomain/index.php/foo. (without showing the index.php).
The problem:
When I try to access my subdomain/temp.html, I get a 500 internal error.
when I remove my root/.htaccess, it works fine. So it's obviously my htaccess file.
I've figured out the problem is that the root/.htaccess rule is being applied to the subdomain, which breaks everything, But I have no ideahow to sort it out.
I've placed an empty .htaccess file inside the root/staging/StagingWebsite hoping it would just over-write any previous htaccess settings, But that didn't work.
EDIT
I fixed the issue specifically but I don't like the solution.
I added a RewriteCond to only run the rewrite rule for as specific domain.
Is there a way to solve this without specifying a domain?
Create /root/staging/StagingWebsite/.htaccess with this line only:
RewriteEngine on
This will overwrite any parent's rewrite rules.

.htaccess - Redirect from subdomain root to subdomain's folder (mod_rewrite/mod_proxy)

Problem
I am trying to redirect from the root folder of a sub-domain, e.g. sub.example.com, to a sub-directory of the sub-domain and keep the sub-domain in the address bar, e.g. sub.example.com/subdir1.
This is not the first time that I have used mod_rewrite, but I am not an expert. I have not used mod_proxy before, but I believe that it will be required for this task.
Background
This is part of a project that I am working on in which the web-host is private, but the server cannot be modified. I am required to specify all sub-domains using their tool, as opposed to creating the rewrites myself. This question pertains to a sub-domain being used as a development site, which will eventually go live without being a sub-domain, e.g. sub.example.com will become sub.com when it goes live. The reason why I cannot simply set the root folder of the subdomain to the directory that I am redirecting to is that the code base for the project relies heavily on the DOCUMENT_ROOT for internal link management, and the target folder, sub.example.com/subdir1, is not the root of the site.
What I have done
I will start by saying that I have exceeded my allotted time to work on this problem, mainly out of interest.
I have done a lot of research and have tried to pull bits and pieces from the sources that I have looked at. However, all but one of the sources that I have looked at only had information for redirecting from a subdomain to a subdirectory of the site's root, e.g. sub.example.com -> example.com/root-subdir. In fact, the only reason that the aforementioned page did have information related to my question is because the user who asked the question accidentally did what I am currently trying to do. Unfortunately, what he did still is not working for me. Here is what I am trying right now (but is giving me a "310 - too many redirects" error):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.example\.com
RewriteRule ^ /subdir1/ [R=301,L]
As previously stated, I think that I may need to use mod_proxy for this, but I have no idea what that would look like.
Any help that you can give would be much appreciated. Thank you for your help! :)
Now if you want to redirect just sub.example.com into sub.example.com/subdir1, then give this a try:
RewriteCond %{HTTP_HOST} ^sub.example.com
RewriteRule ^/?$ /subdir1 [R=301]
The solution given in the comment by #faa did not completely solve my issue, as my real mistake was forgetting to match the root, and only the root, of the subdomain. #faa did, however set me back onto the right track and did answer my question regarding preventing loops. The information that I gained from using his snippet led me to realize what I needed, which I found in the solution to this ServerFault question.
My final solution is the following:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /subdir1/ [R=301,L]
Thank you all for your help!

Rewriting subdomain to subfolder with htaccess

I'm attempting to use .htaccess in the root folder of an Ubuntu/Apache2 server in order to mask a subdomain to subfolder and I keep getting a 500 Internal Error. I know that I'm doing something stupidly wrong and it is some silly error causing the problem. I've checked all of the similar threads on SO and online and whenever I try their advice the 500 continues.
Here's my code.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^admin\.mydomain\.com.*$
RewriteRule (.*) intranet/$1 [L]
What I want to occur is that if a user visits admin.mydomain.com they will get the contents of the folder admin.mydomain.com/intranet/ but their URL bar will still be admin.mydomain.com. Any idea what I'm doing wrong?
In addition, some of the threads online talked about possible problems with this system. Is this the best way of doing this masking, should I be using a vhost setup?
The rewrite rule should work, although I'd probably write
RewriteEngine on
RewriteBase / #omit if in a <Directory> or .htaccess
RewriteCond %{HTTP_HOST} =admin.mydomain.com
RewriteRule ^(?!intranet/).* intranet/$0
Now, you might want to check you Apache error log. It will probably tell you what the error is. My guess is that you did not enable mod_rewrite in httpd.conf.