How to route a path that ends with index.php in Slim framework - slim

I'm using Slim Framework 2.4.2 and my .htaccess looks like this
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
I've been having some trouble with routing a path that ends with index.php. For legacy support reasons, I need to be able to route /soap/index.php to my custom code, but it keeps going to my notFound handler.
I have a route like the following in my /index.php
$app->get('/soap/index.php', function () {
echo "HERE";
});
However, when I go to /soap/index.php in my browser, it get Slim's 404 Not Found handler. I have tried changing the route to /soap/index2.php, which allows me to see "HERE" in the browser, but when I use /soap2/index.php I get the same results as for original. The /soap/ directory does still exist, but /soap2/ does not, so it doesn't seem that it is Apache causing the issue because both return the same results, the Slim 404 handler. It just seems like Slim gives a 404 for any route that goes to an index.php.
I've also tried creating just a /soap/ route to see if Slim is trying to use that when I access /soap/index.php in the browser, but that still gives me a 404.
For now, I will try to just have the 404 handler detect the issue and perform the action.

In the notFound handler, I am getting "/x.php" for the response from $app->request->getPathInfo(). As I add more letters to the front they end up in the string. It's clipping the first 9 characters, which is how long the filename is. After some more looking, this was a known bug.
It is reported on GitHub here.
Updating to the newest Slim framework fixed the issue.

Related

TYPO3: Bingbot creates an ext_form error which get cached

We have a problem whit one of our TYPO3 installations. The Bingbot which visits the site calls a controller of the old ext_form extension without parameters and creates an error.
207.46.13.XXX - - [16/Oct/2018:00:18:48 +0200] "GET example.html?tx_form_form%5Baction%5D=process HTTP/1.1" 200 10256 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
The problem for us is not that this happens but that TYPO3 is caching the site with "Oops, an error occurred! Code: 20181016001848e0153dcf" as content.
Is there a way to say TYPO3 to not cache the site if an error occorres or to send the bot to the 404 site if he calls the site with false parameters.
There are several things you can do:
exclude the page with the parameters in robots.txt (Edit: After consideration this solution is probably unsuitable for the specific problem)
redirect in .htaccess if the page is called without required parameter, a redirect should be recognized by the bot too.
check why the bot is even calling the page without required parameter, perhaps you can avoid it.
bing can be configured for a specific URL, this page can be a starting point for you.
EDIT:
Example for htaccess (not tested):
RewriteCond %{QUERY_STRING} .+
RewriteRule ^example.html?tx_form_form%5Baction%5D=process$ example.html [L,R=301,QSD]
The target example.html can be anything, either a custom 404 page or just the list-view. The code 301 in [L,R=301,QSD] can be adjusted according to HTTP Status Codes (3xx). If it's redirected to a (custom) 4xx page the HTTP status code should be accordingly (404, or perhaps another 4xx-status-message i.e. 400).

How to use URL Rewrite before HTTP Redirect on IIS

So I have a website running on IIS on an address like this: myserver.com/mysite.
From here I made a rule to redirect the site to: myserver.com/mysite/path/to/file.
I did this using the HTTP redirection module to make a 302 redirect to path/to/file and that works fine.
The problem is that if I dont put the trailing slash / at the end of mysite I get a 404 error, so I used the built-in template AddTrailingSlashRule in the URL Rewrite module.
So if I disable the redirect, the trailing slash gets added at the end of the website just fine, but once I enable the HTTP redirect, it sends me to myserver.com/path/to/file/ and obviously that doesn't work, because I get the redirect first and then the rewrite.
Is there a way to change the "order" of the modules? Or is there a better way to achieve this?
Thanks for any help!
For anyone having this problem in the future, I ended up disabling the HTTP redirect and made a new rule using the URL Rewrite module.
It simply matches the ^$ regex and then redirects to path/to/file.
That rule goes after the trailing slash one so with or without the slash, it gets added and only then it gets redirected.

301 Redirect Subdirectory Path to Single Directory

As I am in the process of a site migration, I have been struggling with a 301 redirect issue, and would love some help.
I am going to move an entire domain (www.oldsite.com) to a new domain (www.newsite.com). I planned to accomplish this by changing the DNSto point to the new server. On the new site, I am trying to set up 301 redirects in my .htaccess file to provide a destination for any URLs that will not exist.
Most of the redirects are fine:
Redirect 301 /old-dir-1/ /new-dir-1/
... works fine.
However, if I want to also redirect a subdirectory:
Redirect 301 /old-dir-1/subdir/ /new-dir-1/
... the actual result is:
www.newsite.com/new-dir-1/subdir
I do not want to pass through the subdirectory.
I have tried a ton of combinations and tutorials and Rewrite Rules like:
RewriteRule ^old-dir-1/(.*) /new-dir-1/$1 [R=301,L]
And countless other variations... any ideas?
If anyone comes across an issue like this, here is how I solved:
1) I made sure no application logic was conflicting with the redirects. In this particular case WordPress was also using a redirect plugin which needed to be disabled.
2) I revised the order of the lines in my 301 entries, placing the most specific URLs at the top, and the less specific below.
IE, first:
Redirect 301 /old-dir-1/subdir/ /new-dir-1/
and then...
/old-dir-1/ /new-dir-1/

in htaccess redirect url following a rule

enter code herei have developed a facebook application for example on apps.facebook.com/myappname/, it's a web application hosts on myappname.mydomain.com.
in facebook applications just the url base is different, the second part url is the same, for example:
myappname.mydomain.com/home
apps.facebook.com/myappname/home
myappname.mydomain.com/product
apps.facebook.com/myappname/product
i'd like show just facebook url, not real url so for this reason i need to create a rule redirect in htaccess. i mean a rule which changes just base url from apps.facebook.com/myappname/ to myappname.mydomain.com/
is it possibile? tx, best regards
waiting help i'm working on solution and maybe this is apart of one. in htaccess i added this code
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !apps.facebook.com/myappname$ [NC]
RewriteRule ^(.*)$ https://apps.facebook.com/myappname/$1 [L,R=301]
but as you know facebook application is like an iframe so in this way starts a included loop an my app doesn't work. i need add condition to this rule, "when url is not in facebook iframe" have idea? tx
RewriteCond %{HTTP_HOST} !apps.facebook.com/myappname$ [NC]
This will always be true, because a request reaching your server will never have the HTTP_HOST set to apps.facebook.com. (And the path component of an URL is not part of the domain name …)
The only thing you could do with mod_rewrite in this case is checking the HTTP Referer, I guess – if it’s anything else than apps.facebook.com, then your app is likely being called outside of the FB iframe. (But how unreliable the referer is, should be common knowledge by now.)
Your best bet is to use JavaScript to check if your app is being called within an iframe or on it’s own (and if it is in an iframe, assume it is on apps.facebook.com.)
if(top == window) {
// not in iframe, redirect:
window.location.href = "{your app’s URL on facebook}";
}
This would fire only if your app is called directly in the top browser window – if it is framed, no matter if on facebook.com or not, this code will do nothing.
You could add an X-Frame-Options header in your server config, so that your app will only be allowed to be displayed in an (i)frame on apps.facebook.com, and not anywhere else. If you combine that with the JS approach, you can be pretty sure that if your app is “framed”, it is on apps.facebook.com and not somewhere else.
after two working days i understand this, tx for your reply, this is my javascript solution
<script>
if (parent.location.href == self.location.href) {
window.location.href = 'https://apps.facebook.com/myappname' + window.location.pathname;
//alert(window.location.pathname);
}
</script>
PS. tx to MAX!!!

IIS6 - How do I redirect users to another site for every page with a few exceptions?

I have a website setup in IIS 6, let's say it's called http://www.this.com.
I have setup a redirection for this website to http://www.that.com which maintains the directory structure and query parameters as follows:
http://www.that.com$S$Q - using the option "The exact URL entered above"
This works great, whenever someone requests, for example:
http://www.this.com/subfolder/page.aspx?Id=1
then they end up at:
http://www.that.com/subfolder/page.aspx?Id=1
Now, I have one page, actually a handler, http://www.this.com/image.axd, which I do not want to redirect.
What is the syntax for that? I've read the Redirection Using Wildcards section here, but I can't work out how to do what seems to be something straight forward.
Note that image.axd is a handler so I can't just "right click" on it and set the redirection properties as it doesn't physically exist.
I also have a couple of other pages in subfolders which I do not want to redirect, for example:
http://www.this.com/subfolder/donotredirectthispage.aspx
Any help would be appreciated.
Edit: A couple of people have mentioned using ISAPI_Rewrite, for which I'm grateful, but I really don't want to introduce another complexity into the website configuration. IIS seems to imply I can acheive what I want using the ! and 0 through 9 variables.
Is it really not possible to do this using IIS?
My current workaround is to set the redirection properties on ALL folders and pages that I want to redirect except those I do not, but this is a management nightmare.
You could implement a custom error page for the page not found error (404) that does the redirection for you. You'd turn off the redirection in IIS. Build the logic for the redirection in your custom error page. Then configure your web site so that 404 errors redirect to your error page.
If you can install software on your IIS server, I'd recommend using a tool to rewrite your request URLs.
For IIS 6.0 I've used ISAPI_Rewrite and it works really well. It's lightweight and very configurable. There's a "Lite" version available for free and will support your requirements.
You configure the program using a text file containing rules that match HTTP requests and then write actions to perform once a rule is matched. Your instance would probably require a general redirect rule (similar to the one in IIS) and rules for your exceptions.
You should look into the possibility of using a header rewrite module, for example ISAPI_rewrite. There is a free "lite" version available that is enough for your needs.
What this can do for you is the following: Before actual pages are executed on the server, the Request headers are rewritten (or HTTP 301/302 redirects are issued) based on a configurable set of rules. The underlying server sees the remaining requests as if the client really made them in that fashion.
The following rules would leave image.axd requests alone, while redirecting everything else.
# image.axd stays unchanged ("L" is the "last rule" flag)
RewriteCond Host: www.\this\.com
RewriteRule ^.*?\bimage\.axd\b.* $0 [L]
# all requests that have not been stopped by an earlier rule
# end up here ("RP" is the "permanent redirect" flag)
RewriteCond Host: www.\this\.com
RewriteRule .* http://www.that.com$0 [RP,L]