Rewrite rule 404 issue with site hosted on WPE - laravel

We have a tricky setup hosted on WP Engine which has a must-use plugin that uses Laravel.
The goal was to totally eliminate WP from the fetches that the plugin would catch and process.
On my local machine I managed to write such rule for IIS in a few minutes, but eventually needed to install Local WP to be able to come up with a rewrite rule that would work under nginx.
Here is the nginx rule that works within Local WP, that's based on the regular WP permalink rules:
location /api/v2 {
try_files $uri $uri/ /wp-content/mu-plugins/xxx/server/public/api.php$is_args$args;
}
Now, this does not work on our WPE dev site. It obviously loads the correct file, because the 404 screen I get is coming from Laravel, but it seems that everything that goes after /api/v2 got striped or not being included.
A full query would look like this:
/api/v2/admin/members?limit=10
Here's the original rewrite rule I added to IIS:
<rule name="XXX Api" stopProcessing="true">
<match url="^api/v2/(.+)/?$" ignoreCase="false" />
<action type="Rewrite" url="wp-content/mu-plugins/xxx/server/public/api.php" appendQueryString="true" />
</rule>
Can anyone please help me to figure out why the rewrite returns Not Found on WPE, but works on Local WP?
Edit:
Actually, I just dumped the request URi for this particular address.
On Local WP it's the following:
"http://xxx.local/api/v2/frontend/members"
vs. on WP Engine:
"https://xxx.wpengine.com/wp-content/mu-plugins/xxx/server/public/api.php/"
So, it doesn't seem like the rewrite works at all on WPE, it only points to the correct file.

Related

Odd 404 during URL rewrite

Background: I'm forwarding incoming 80/443 traffic to \\SERVER2; TFS is running on \\SERVER3. I wish to route all TFS-related requests to \\SERVER3. I have to do it this way as I'm running Server Essentials on \\SERVER2, which is finicky enough to not work well under URL rewriting (almost as bad as SharePoint, but not quite).
Here's the only rule on the default website:
<rule name="TFS Rewrite" stopProcessing="true">
<match url="^tfs(.*)" />
<action type="Rewrite" url="http://server3:8080/{R:0}" />
</rule>
...and here's the Failed Request Log: https://1drv.ms/f/s!AodXF_j3BiWkhPAZwjnwC-rAecVgtw
Note the requested URL on line #87 of the PDF: http://server3:8080/tfs. I can browse to that internally just fine. The external URL is https://tfs.domain.com/tfs.
The next entry that's at all file-specific is the 404 itself, on line #165.
I just don't get this. It's a simple rule. Why would IIS turn up a 404 for a clearly valid and working URL?
EDIT
As a test, I added this condition:
<conditions>
<add input="{HTTP_HOST}" pattern="tfs.domain.com" />
</conditions>
Now if I browse to https://tfs.domain.com/, the default website loads.
This—together with the logs—would seem to indicate that while IIS is rewriting the URL, traffic isn't actually being routed to \\SERVER3.
What's going on here? This is a mystery.
OK, I got it working.
I'd installed both the URL Rewrite and ARR Modules, but I hadn't yet enabled proxy processing.
I created a dummy Reverse Proxy rule and was prompted to turn it on in IIS. I did so, deleted the dummy rule and now all is working as expected.

301 Redirect plugin for wordpress on windows server

I has a wordpress site on azure website, traditionally I has used Quick Redirect Plugin to redirect some pages to new pages, but this plugin not work on windows cuz is using web.config file instead .htaccess
There are any way to generate 301 redirects for certain page from wordpress when is hosted in windows server, I has searched some plugin to do this but not finded any.
MORE DETAILS:
Azure websites use subdomain for azurewebsites.net like myblog.azurewebsites.net, I am configure website url with other masking domain name and work well, but, I want to that when user browse myblog.azurewebsites.net/category/link redirect to www.mydomain.com/blog/category/link but with 301 redirect in web.config. I am traying several ways, with location and url rewrite but nothing work.
Example of rules used:
<rule name="CanonicalHostNameRule1" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="subdomain\.azurewebsites\.net/([_0-9a-z-/]+)" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" />
</rule>
Are you hosting your website with Project Nami?
Your wordpress site should still be using .htaccess, although I may be mistaken.
For redirection, I use Page Links To.

How to get IIS Express to serve static content above the root

My home page, which is in my web root, has a relative url that starts with ../../lib/, so ../.. is above the web root.
When I try to serve my site with IIS Express, I get a 404.
How can I get this to work without moving the resources or changing the urls in the html page?
There might be a more direct way of doing this, but this is possible by adding the following to the web.config.
I noticed the 404 url was as if it was at the root, so the match url is at the root. I guess it just ignored the ../.. when interpreting the route.
First I set up a virtual directory on my local IIS to serve up the files above the root. I called it lib and pointed it at the content above the root. The actual path shown here is what I needed and just serves as an example.
<system.webServer>
<rewrite>
<rules>
<rule name="Files Above The Root" stopProcessing="true">
<match url="lib/(.*)" />
<action type="Redirect" url="http://localhost/lib/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
I'm using IIS Express just for debugging and it bears no relationship to how the site works in production. Coloring outside the lines is OK when it's just for debugging. The site build doesn't depend on this at all, and the config doesn't interfere with the site running in an actual environment because no urls are ever going to match this path.

Duplicate domain in URL or Domain/AppName

I'm sure this is a simple issue, but I have noticed that when I host (shared host on GoDaddy) a website the URL repeats the Application name.
Example, I have http://makedifferences.org, if I go to this its fine, but if I click a link it takes me to http://makedifferences.org/makedifferences/...
It's not just this one site, it's all my sites on GoDaddy and I think it may be the same on my sites hosted elsewhere, but I can't check them rite now.
I'm not using web deploy to deploy it, as my first thought was it had to do IIS. My guess is that it must be a setting in Publish Settings, but I played around with them and couldn't seem to get it to go away.
Any advice would be appreciated.
Thanks,
Garrett
Update
This is apparently not a mvc thing as I check on a site I have hosted at dotnet-host.com and it doesn't have this problem. So I guess it is something with my settings at Godaddy.
I have deleted the folder and setup a virtual folder and this did not fix the problem.
I have multiple site hosting through them and my domain name A record is my dedicated IP for all the sites, then in host's domain management I point the domain name to the folder the site is in.
I think this is the correct way to do this but am not sure.
To restate my problem now that I know a bit more about it, if I type in http://makedifferences.org/Charities/Details/3 the page loads and everything is perfect. But if I click a link on the home page to go there the url is http://makedifferences.org/makedifferences/Charities/Details/3
Thanks why I thought it was a setting in Visual Studio.
There are two things that cause this behavior.
Your Application is installed in a folder instead of root directory for the shared hosting.
Your DNS settings point the domain name to this folder.
I suppose you are hosting multi-websites in shared hosting.
To get rid of this problem, you need to go in the IIS settings and set these folders as virtual directories.....Or create one for each website....And then install your application in that folder.
UPDATE
This is actually not an issue related to GoDaddy shared hosting at all but an issue with hosting an ASP.NET MVC site in a virtual directory. When you use the shared hosting provided by GoDaddy you get a root folder and limitless subfolders, each of which can be its own domain, by way of virtual directory. Unfortunately, MVC’s routing engine produces URLs that will include the virtual directory name appended to the domain name.
For example, let’s say you have a domain named http://www.example.com and your folder/virtual directory name is /File. If you take the MVC template project without making any modifications and upload it to your folder and then go to your url everything will look fine. You will notice the ‘Home’ and ‘About’ tabs at the top right of the page. When you click on the ‘About’ tab, since it is routed to the Home controller’s About action, you would rightly expect the URL to be www.example.com/Home/About. What you will see, though, is that the URL generated by the ActionLink method includes the name of the virtual directory. Therefore, the URL will be www.example.com/File/Home/About.
To get rid of this problem, add the following code to your Web.config’s system.webServer element
<rewrite>
<rules>
<rule name="Remove Virtual Directory">
<match url=".*" />
<action type="Rewrite" url="{R:0}" />
</rule>
</rules>
</rewrite>
Solution seeked from HERE
Best of luck :-)
To work in all cases I used rewrite rule:
<rewrite>
<rules>
<rule name="Remove Virtual Directory">
<match url=".*" />
<action type="Rewrite" url="{R:0}" />
</rule>
</rules>
</rewrite>
And the function bellow:
protected void Application_BeginRequest()
{
#region Godaddy shared host fix - Detect VDIR in url and remove
//verified that HTTP_X_ORIGINAL_URL keeps the original url (withoud domain) before url rewrite module,
//that way can check if the virtual directory name is at start, and remove it.
if (Request.ServerVariables.AllKeys.Contains("HTTP_X_ORIGINAL_URL"))
{
var origUrl = Request.ServerVariables["HTTP_X_ORIGINAL_URL"];
var matchVdir = "/" + Myproj.Core.Constants.Environment.HostingVirtualDirectoryName + "/";
if (origUrl.StartsWith(matchVdir))
{
var urlFix = Request.Url.GetLeftPart(UriPartial.Authority) + "/" + origUrl.Remove(0, matchVdir.Length);
Response.RedirectPermanent(urlFix);
}
}
#endregion
}

intercepting url rewrite module, prevent rewrite

Is there anything that would cause the url rewrite module in IIS to not fire off? Maybe a site that is in integrated mode or an http handler?
I have tried a few different things to get the rewrite rules to work but nothing. My latest is as such
<rewrite>
<rewriteMaps>
</rewriteMaps>
<rules>
<rule name="rewriterule" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<action type="Redirect" url="http://www.google.com" />
</rule>
</rules>
</rewrite>
and it doesn't work at all. I've tried various regex, etc. Its like it doesnt get used.
Seems like you have your answer but here are some other possible things that might cause Rewrite Module not to work :
When you deploy your web site and see this feature not working on
your server, it is highly possible that you misconfigured something
on your server. One of the misconfiguration you might have done could
be setting the overrideModeDefault attribute to Deny for rules under
<sectionGroup name="rewrite"> inside your applicationHost.config
file.
If you are on a shared hosting environment and you see this feature
not working, then ask your provider if they have given you the
permission of configuring this part.
In your development environment, if you run your web site under
Visual Studio Development Sever, you won’t be able to see this
feature working. You need to configure your application to run under
at least IIS Express to see this feature working.
The answer in my case is that you have to be running the site in the same target platform as the url rewrite module. for example, I have x64 version of url rewrite module installed but the site was running under 32bit. Once I setup the site to run under 64bit, the rewrite started working.

Resources