8
votes
A very simple router for a PHP application
There are many takes at that. And the most suggested one is to use a ready-made framework. But assuming this code as is:
First of all, I don't see the real need for this router. Why not to request ...
5
votes
A very simple router for a PHP application
I'm just going to comment specifically on the first two lines of the htaccess.
ErrorDocument 404 /inc/index.php
ErrorDocument 500 /inc/index.php
That is asking for ...
5
votes
Serve rescaled jpg images on demand with myphoto!500.jpg syntax (here 500px-width rescaled)
If this were my code I'd be totally distrustful of the URI presented by my user. In other words I would assume that the results of the explode operations $f, ...
3
votes
Accepted
Serve rescaled jpg images on demand with myphoto!500.jpg syntax (here 500px-width rescaled)
Analysis
The code looks acceptable; it is not difficult to read. The description does not state which image formats should be supported however the code appears to output resized images as JPEG images....
3
votes
A very simple router for a PHP application
Quite aside from the above comments it's worth reading up on the PSR1 PSR2 and PSR12 linting rules. It has simple rules like a space after the if keywords if ( and ...
3
votes
Accepted
Uploading and showing images securely
First, to your questions
Do you spot anything wrong regarding permissions?
Overkill. Permissions has very little to do with web-servers, as there is only one user - one under which a web-server (...
3
votes
Accepted
HSTS Recommendations in .htaccess
There are two aspects to HTTP Strict Transport Security (HSTS):
Implementing HSTS on your site.
Submitting your already HSTS enabled site to the HSTS preload list. This is where the "list of ...
3
votes
Accepted
.htaccess Recommendations
https://gtmetrix.com/ notes that redirects are the largest culprit in slowing down my page loads
gtmetrix.com's "suggestion" in this regard is arguably &...
3
votes
Protect against XSS with .htaccess file
The common definition of XSS is that code faults which allow someone to manipulate your website appearance, access prohibited sections of data, view inaccessible files or possibly steal credentials ...
3
votes
Accepted
Adding, removing, and changing user names and passwords in .htpasswd with PHP
Here is my version based on two personal preferences: I hate scroll bars and I hate repititions. Hence I prefer everything typed once and also I like my code being fully visible in the default code ...
2
votes
Adding, removing, and changing user names and passwords in .htpasswd with PHP
For the sake of your code and mine, I hope that the usernames cannot contain any colons since that is the delimiting character between usernames and passwords!
I have a bias toward regex because I ...
2
votes
Suggestions on how to improve this .htaccess file for page load speed
You can improve this code by removing unnecessary repetition. If you put a trailing slash after each declaration, then you do not need to repeat the same code over and over again. I would also suggest ...
2
votes
Accepted
Load other files (from outside public_html) under index.php
Preface
I wouldn't use the query string of the URL at all.
The problem with using GET, is that GET is meant for other things such as bookmarkable search link etc. As you add more ...
2
votes
Load other files (from outside public_html) under index.php
You can simplify your regex pattern and you might like to combine your validation with the preparation step. The following pattern is just like yours except it allows a single trailing slash and ...
2
votes
Accepted
Customized Apache host files
You don't actually need ServerName and ServerAlias directives for your port 80. This is due to the fact that your are using port-based virtual host. The "*" in the tag indicates that all incoming ...
2
votes
Accepted
Apache2 mod_rewrite directive
It's an Apache config file. It isn't going to look pretty. :)
That being said, I don't understand why you have RewriteCond specified for any of these rules. What is that condition preventing? The ...
2
votes
.htaccess using public folder and SEO friendly URL
Redundant RewriteEngine declarations
Unused match group in (public)
Escaping (using \) is ...
2
votes
Accepted
Directory listing in a web server
The variable $i is not used in the whole program. You should remove it.
You output the <a> elements before the ...
2
votes
Protect against XSS with .htaccess file
Neither you .htaccess file or your .php file would be Vulnerable to Xss Attacks as they are both server side scripts which would never be Shown to a user & therefore would not be easily ...
2
votes
Best way to deny .php in URLs while keeping access to those files through other URLs?
As I mentioned in a comment on your StackOverflow question: Your solution is very specific, it only works for those two cases. You could create a more general rule.
Something like: "Every url ...
1
vote
Accepted
Understanding htaccess redirect to HTTPS and WWW
The code above works as expected. Why isn't the code in the next format, as it does the same thing? Is any difference ?
...
1
vote
Accepted
Direct to another folder with .htaccess file
The line you are using is telling the engine, redirect everything to the following URI. The reason for this is that you are using the pattern matching wildcard (.*).
The parenthesis is used for ...
1
vote
Accepted
Rewriting domain only if not on local dev enviroment and forcing www with Mod Rewrite
Yes! That is indeed correct. From the docs for RewriteCond:
'ornext|OR' (or next condition)
Use this to combine rule ...
1
vote
Redirecting HTTP requests to HTTPS
Since your actual machines are being handled by the Cloudflare based forwarding, you can let them handle the enforced SSL and www-prefixing rules instead.
However, ...
1
vote
Accepted
Redirect http to https, non-www to www and "/index.php" to "/"
Keep your code consistent. If you are using RewriteRule, use the same capitalisation format in all declarations. Same for setting the flags (...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
.htaccess × 48php × 18
security × 9
url-routing × 7
regex × 6
https × 5
cache × 4
performance × 3
file-system × 3
html × 2
image × 2
error-handling × 2
mvc × 2
api × 2
linux × 2
html5 × 2
url × 2
server × 2
ssl × 2
javascript × 1
beginner × 1
object-oriented × 1
css × 1
http × 1
ajax × 1