Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [.htaccess]

Directory-level configuration file used by Apache web servers.

Filter by
Sorted by
Tagged with
5 votes
3 answers
1k views

A very simple router for a PHP application

/.htaccess ErrorDocument 404 /inc/index.php ErrorDocument 500 /inc/index.php RewriteEngine ON RewriteRule ^([a-z_-]+)$ index.php?page=$1 [L] /index.php ...
Nathan George's user avatar
4 votes
0 answers
67 views

Serving Laravel public/ contents when all Laravel files are in the same server directory

I have a Laravel 8 project hosted at xxx/laravel/ on an Apache server, where xxx is the domain. I want to serve the contents of <...
Ichi's user avatar
  • 93
5 votes
2 answers
205 views

Serve rescaled jpg images on demand with myphoto!500.jpg syntax (here 500px-width rescaled)

On web pages, obviously large photos (e.g. 4000x4000px) cannot be served with a reliance on CSS to do the resizing: it would be too slow for end users and too bandwidth-consuming for the server. So it'...
Basj's user avatar
  • 264
0 votes
1 answer
82 views

Understanding htaccess redirect to HTTPS and WWW [closed]

I have some questions about a code I found on stackoverflow. The code does what I want to do. Redirects to HTTPS and WWW when doesn't exist in URL. But, I want now to understand what I'm doing. So, ...
Andrei's user avatar
  • 51
4 votes
2 answers
491 views

Adding, removing, and changing user names and passwords in .htpasswd with PHP

Here is some code I wrote to add, remove, and change user names and passwords in .htpasswd with PHP: ...
tony's user avatar
  • 361
5 votes
1 answer
730 views

HSTS Recommendations in .htaccess

Please see my previous post in the below hyperlink I've updated my .htaccess file to account for an HSTS, along with many of the recommended changes. See the ...
user avatar
4 votes
1 answer
223 views

.htaccess Recommendations

I have a personal website that's used primarily for fun. I upload images, videos and text that I want to share. An HTML submission form accepts questions and string submissions from users, which uses ...
user avatar
2 votes
0 answers
97 views

.htaccess template

I have an .htaccess template I have been working on that I want to submit for code review. I want to accomplish these things: Custom error handling Remove index.php if in url Force HTTPS Remove www. ...
tony's user avatar
  • 361
2 votes
0 answers
73 views

Apache reverse proxy security configuration

Could someone share some light and check if this is okay for apache httpd security/good standards? I'm using apache httpd to call my Node.js app that is running with Express and also configuring SSL. ...
xDG's user avatar
  • 121
3 votes
0 answers
78 views

.htaccess file to enable compression, send security headers, and set cache expiration

This is the current .htaccess configuration for one of the website projects that I am working on, just as a learning exercise. This is working code and everything ...
Ryan Stone's user avatar
1 vote
0 answers
553 views

Implement versioning of a RESTful API with PHP/Slim and Apache

I want to create a RESTful API with Apache/PHP and the Slim Framework (3.x). The API should support URI-based versioning like ...
CachingFoX's user avatar
4 votes
2 answers
2k views

Load other files (from outside public_html) under index.php

I wanted to load every page under index.php with a simple index.php?do=login For example when the link index.php?do=login or <...
J. Doe's user avatar
  • 183
3 votes
1 answer
363 views

Uploading and showing images securely

I've read various posts about how letting users to upload files can create vulnerabilities to your website such as a user injecting PHP code in an image. So I've created a small test project where ...
captain monk's user avatar
0 votes
1 answer
49 views

Direct to another folder with .htaccess file [closed]

Lets say my folder structure looks like this ...
yusuf tezel's user avatar
1 vote
1 answer
39 views

Rewriting domain only if not on local dev enviroment and forcing www with Mod Rewrite

I'm trying to write some mod rewrite code to redirect pages on a site to always use www and this has been working fine: ...
Brett's user avatar
  • 165
4 votes
1 answer
58 views

Redirecting HTTP requests to HTTPS

I have read a lot and spent a lot of hours trying to reach the right way to set a good htaccess in order to redirect an HTTP site to HTTPS. There are a lot of tutorials on the Internet, even on Stack ...
eplazai's user avatar
  • 141
5 votes
1 answer
129 views

Redirect http to https, non-www to www and "/index.php" to "/"

Is this htaccess code the best/proper way to: Send all http traffic to https Send any visits to index.php to the URL that doesn't show "index.php" Send all non-www traffic to www This code works ...
user3304303's user avatar
2 votes
1 answer
55 views

Customized Apache host files

I'm using customized Apache host files for my Digitalocean websites. Please review the code, whether it's following the good standards or not, and please mention if I'm missing something important. ...
user95626's user avatar
1 vote
1 answer
273 views

htaccess with compression, caching, and rewrite rules for SEO

I have the following htaccess and I want it to be the perfect htaccess for my website so that it uses less bandwidth and meets the requirements of a good SEO. I am on an apache server and my files ...
Ayan's user avatar
  • 231
2 votes
1 answer
25 views

Apache2 mod_rewrite directive

The website I'm working on is essentially project-management software. Each project has a code (alphanumeric lowercase, with hyphens). The URL must include the codes and treat them as directories. <...
Dellowar's user avatar
  • 267
4 votes
1 answer
647 views

.htaccess using public folder and SEO friendly URL

.htaccess is not my strong suit. Is there any there can optimize this code? ...
TheCrazyProfessor's user avatar
-3 votes
1 answer
467 views

Directory listing in a web server

I have Ubuntu 16.04 with standard apache web server installed. Nothing special about it. No open ports but 80. Instead of the default index page I put this one: ...
Nlandau's user avatar
  • 13
0 votes
2 answers
4k views

Protect against XSS with .htaccess file

My .htaccess redirects everything to my index.php, but I wonder if it's vulnerable to XSS attacks. Am I safe? .htaccess file ...
Sample_d's user avatar
5 votes
2 answers
307 views

Securing PHP using a gateway that consults a whitelist

My site was recently infected and running malicious scripts. Once I discovered this, I cleared everything, the hosting company re-initialized the VPS and I setup my site anew. This is how I run my PHP ...
BeetleJuice's user avatar
1 vote
1 answer
161 views

Basic settings, custom error page, dynamic versioning, rewrite rules

Any suggestion is more than welcome! I had to do a few tricks in rewrite rules (checks on ENV:REDIRECT_STATUS) to avoid infinite loops, but it works fine. error....
Tommaso Belluzzo's user avatar
7 votes
1 answer
7k views

Creating an object-oriented router class in PHP

On my way to learn OOP, I am developing a little CMS using the MVC pattern. I would like to have some feedback about my router class, mostly about if I am correctly using OOP. Right now, I have a ....
ThemesCreator's user avatar
2 votes
1 answer
202 views

Complex .htaccess

After 8 years with the same Apache webserver, the .htaccess file seems to be a bit heterogeneous. I have taken some care about readability, but there are still some problems (such as pages with www. ...
jcrs's user avatar
  • 31
4 votes
2 answers
78 views

301 Redirecting

Is there anything I could do to improve the following .htaccess code? ...
Kid Diamond's user avatar
  • 2,591
2 votes
2 answers
177 views

Prettifying URLs for a PHP-based club website

I have a website for my car enthusiast club ("example.org") whose content can be divided into three main sections: Startseite (the "front page" of the site), Mitglieder (membership directory), and ...
C.E.'s user avatar
  • 193
5 votes
2 answers
53 views

Mapping several URLs to one login page

My htaccess has this block in it: ...
atdc's user avatar
  • 53
5 votes
1 answer
327 views

Redirect for subdomains and secondary domains

I've just edited my .htaccess file. All works as it should, but I'm not too familiar with regular expressions and want to make sure that there aren't any unintended ...
amylynn83's user avatar
2 votes
2 answers
103 views

301 redirect using .htaccess

I wonder if the following 301 redirect is the best way for my situation. I used this post on SO to give me the following 301 redirect: ...
luke_mclachlan's user avatar
7 votes
1 answer
130 views

An .htaccess for our entire site

We have this long .htaccess mainly rewriting our URLs. Everything works fine (except blog titles containing a ' , but we're ...
G.EGCB's user avatar
  • 73
0 votes
2 answers
1k views

All-purposes AJAX handler made with PHP and .htaccess that speaks JSON

In a project I've started, I decided to implement some new code to handle AJAX requests. The requirements are that it can ONLY access the /ajax/ folder, load ...
Ismael Miguel's user avatar
1 vote
2 answers
1k views

Redirecting all pages under a certain directory to a single file

I want to redirect all pages under a certain directory to a single file, like so: /dir/a/dir/new ...
Charles's user avatar
  • 509
3 votes
1 answer
41 views

Faults using mod_rewrite

I never really bothered using mod_rewrite to achieve SEO friendly names but I've always admired from a distance because I've never been good at regex. The below .htaccess file does work, but I'm ...
zanderwar's user avatar
  • 421
4 votes
0 answers
170 views

.htaccess index.php removal, static content serving

I am writing a CMS type application and I am trying to restrict how the server gets accessed. Any content (in js/, css/ or images/ directories) should be served as is, as long as there is an index....
CJ Dennis's user avatar
  • 249
2 votes
1 answer
57 views

Forcing SSL and WWW using .htaccess

I would like to know if this code in .htaccess for forcing SSL and WWW in URL is correct, because with another code I usually get redirect loop, e.g. ...
user2406937's user avatar
3 votes
1 answer
373 views

htaccess for URL remapping, caching, and compression

I have been collecting snippets from all over the place and then put them all together creating the following .htaccess file. I really don't understand if what I have done below is good/should work ...
Leo's user avatar
  • 789
15 votes
1 answer
414 views

Portable website template

I have spent the last 6 months as I am studying web development in college to build a website template that is responsive and accessible from as many devices and browsers as possible. I would really ...
Leo's user avatar
  • 789
4 votes
1 answer
217 views

Review URL-prettifying .htaccess file

Can anyone please review the following .htaccess file and let me if it is correctly put together? What I think it does: So it direct to a custom 404 page Remove ...
Leo's user avatar
  • 789
3 votes
0 answers
2k views

Automatically redirect /index.php files to their URL directory with .htaccess

The requirements: Work inside .htaccess (preferably via mod_rewrite) Redirect requests from /any/directory/index.php to ...
Baumr's user avatar
  • 171
2 votes
2 answers
816 views

Is it ok to use PHP's strpos and substr altogether in one statement?

I am using PHP to build a REST API. I want to receive requests from the URL in the following format: http://mydomain.com/api/format/method?app_id=value&call=encrypted_request So, I have modified ...
gentrobot's user avatar
  • 283
2 votes
1 answer
121 views

Can my router code be improved?

I have created a nice url structure for my site. In my .htaccess I have: FallBackResource /index.php And in my router class I have: ...
imperium2335's user avatar
7 votes
1 answer
290 views

Canonicalize URLs for static website

I want to "canonicalize" URLs for my static (files and folders) website. The 'Aims' describes what I want to accomplish. The 'Code' gives my current .htaccess. ...
unor's user avatar
  • 2,613
6 votes
2 answers
229 views

Suggestions on how to improve this .htaccess file for page load speed

Here is my standard .htaccess file, any suggestions on how I can improve it with regards to page load speed? Would gZip instead of DEFLATE make any sort of difference? ...
Sam's user avatar
  • 193
8 votes
2 answers
6k views

MVC router class

Below is what I have come up with for a router/dispatcher system for my personal framework I am working on. Can you please review and tell me any improvements that could be made? The first part is ...
JasonDavis's user avatar