.htaccess rewrite to unmounted folder resource - apache

Im trying to use a .htaccess file on an apache server to point /cmsfiles/flipbooks/thisFlipBook/ to /thisFlipBook
Ive tried:
RewriteRule ^/thisFlipBook/ /cmsfiles/flipbooks/thisFlipBook[L,R=302]
as well as:
RewriteRule ^/thisFlipBook/cmsfiles/flipbooks/thisFlipBook[L]
(without the R tag so that mod_rewrite knows its an internal apache redirect instead of having the browser send a new request for the rewritten resources.)
The first rule results in a 404, and the second results in:
/thisFlipBook/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/
However if you manually navigate to /cmsfiles/flipbooks/thisFlipBook it manages to find the index.html file and load it successfully.
Am i doing something wrong?
Also: server side apache redirects and unmounted folder are the correct way to be doing this right? Client started requesting so many flipbooks that we've moved them out of the project for deployments sake.

Related

Specify to load index.html file for every request in apache config file

I have a React application hosted on my server and I need to always load index.html file for every request users make.
Let's say that I have a website that has the address xyz.com, and the root directory contains the React build files, including this index.html file. There are many routes that users can specify to access to certain parts of the website, for example to register on the website they can access xyz.com/register. So, what I want to accomplish is instruct server to always serve this index.html every time users access my site, even though they are visiting different routes of the website.
So I'm assuming that this is something that I can set up in the .conf file for the website, and if it is, can you please let me know how I can achieve it?
You can use the below rewrite rule.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule .* /index.html [L,R=302]

Apache 2.4 Internal mod_rewrite is not working

I have the following excerpt in my .htaccess file:
RewriteEngine On
# Whether RewriteBase is commented does not appear to have an impact on my problem
# RewriteBase /
RewriteRule ^admin/(.*) members/$1 [L]
The idea is that the pages in /admin load from the /members directory, since certain features are duplicated between them, so that I don't have to duplicate my code. (There are other directives in the file that are related to a CMS system, and those are working as expected.)
On the current Apache 2.2 server, everything works fine. My client's webhost wants to upgrade to a server with Apache 2.4, and on the test server the rewrite rule fails. Instead of loading the page, it just displays "File not found."
All other rules are executed as expected, it's just that one that fails. I have tried adding/removing / characters and removing [L] from the rule, it always fails. I tried adding [R] to send the redirect to the browser, but even that failed. But if I change the url to the same filename but in the members directory, then the file loads successfully.
Being able to change one directory name to another seems like a pretty basic function of mod_rewrite. What am I missing?

Redirect a forbidden URL in Apache

I would like to move an entire directory and its subdirectories from one Apache server A to another Apache server B, and then create a redirection from A to B.
i.e.
http://server_a.com/docroot/dir to http://server_b.com/docroot/dir.
This is what I did:
I copied the files and directory structure under dir from A to B
I deleted the directory dir on A
I created a rule in docroot/.htaccess on server A that reads
Redirect permanent dir/ http://server_b.com/docroot/dir/
But when I go to http://server_a.com/docroot/dir/path/to/file/index.html, I get a 403 Forbidden, even if the target page http://server_b.com/docroot/dir/path/to/file/index.html is up.
I know that the .htaccess is read by Apache, because it correctly controls other parts of server_a. I am not root on these servers. I have also tried with a RewriteRule, with the exact same results.
How should I go about creating a redirect in this case? Thanks.
If you have mod_rewrite enabled than you can do this
RewriteEngine On
RewriteRule ^/?docroot/dir(/.*)?$ http://server_b.com/docroot/dir$1 [R=301,L]
Put it in your .htaccess file in the Document Root directory http://server_a.com/.
Note:
Delete you Browser cache first.
You'll need the leading / in the old URL. Like this:
Redirect permanent "/dir" "http://server_b.com/docroot/dir/"
See the mod_alias docs for more details.

htaccess 301 redirect "works" but I get a 404 error at new site

Sorry for such a long title, but it pretty well describes what is happening.
Details: I have two sites, different domains. Previously, I had a temporary site in a not-visible, but published directory in the older domain. Only those who had the extra directory (or the extra path would normally see the temporary site).
Now that I have a new domain and a permanent new site, I simply want to redirect any attempts to access the old directory/pages/site. Here is the line I added to the old site's htaccess file (last line, BTW):
redirect 301 /mailscamalert.com/weather2/ http://www.mid-southweather.com/
That "works" at least in the sense that the user ends up at the new site. But that site throws up a 404 'flag' and the user ends up at my "erer" page. All the new site's navigation is on that page, of course, but it is probably very confusing!
I've tried removing the trailing "/" on 'weather2/' and/or "...com/", adding
"index.html" to the new site's url. No change in ending up at the error page. Also have tried "meta" redirects and even a bit of php:
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.mid-southweather.com/index.html");
Any helpful suggestions or links, greatly appreciated!
Thanks!
Please correct your rewrite rule to the following:
RewriteEngine On
RewriteRule ^weather2/ http://www.mid-southweather.com/ [R=301,L]
If you had multiple pages in that directory and want them all to redirect to your new target domain, do this:
RewriteRule ^weather2/.* http://www.mid-southweather.com/ [R=301,L]
Your current rewrite rule appears to append the actual directory you are trying to redirect to the target url.
Location: http://mid-southweather.com/weather2/
As I discovered using live http headers extension. That weather2 directory of course doesn't exist on your new site, thus the 404.
Just dump your lines and replace them with mine and it should all work nicely. And undo any other changes you may have done in the process of trying to get it working.
Make sure you don't have other rewrite rules going on, it looks to me like you might have one more running somewhere.

Apache mod_rewrite redirecting page assets

I just started using mod_rewrite for a web project, and I had finally got it to redirect the way I wanted but I have ran into a big problem. If I redirect the request /trades/id to trades.php?id=id, the browser looks for all of the assets of trades.php inside of the non-existent trades/ directory instead.
Here is my .htaccess
# Enable Rewriting
RewriteEngine on
# Rewrite user URLs
# Input: trades/ID/
# Output: trades.php?id=ID
RewriteRule ^trades/(\w+)/?$ index.php?req=trades&id=$1
The problem that arises is that when I load the page localhost/trades/ID, The browser is attempting to load assets like so,
http://localhost/trades/js/cardy.js
which ofcourse does not exist on the server. I'm still really new to mod_rewrite, so I'm not sure how to fix this problem.