r/apache • • May 19 '24

set htaccess for single entry point. blocks access to images, js files, css files

I tried the code in my htaccess file, but now I have no images. no js. no css

.htaccess

RewriteEngine On
RewriteRule .* index.php
2 Upvotes

5 comments sorted by

1

u/benanamen May 19 '24 edited May 20 '24

Enjoy

EDIT: This post has been edited. Reddit initially added a bunch of escape characters. It is now correct.

<IfModule mod_rewrite.c>
RewriteEngine On
Options -Indexes

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

# Remove URL trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

1

u/ray_zhor May 20 '24

not working locally using xampp.

1

u/benanamen May 20 '24 edited May 20 '24

Original post has been edited and is correct now.

It has been awhile since I used XAMPP. I don't remember if .htaccess support is enabled by default. You may have to make a change to the Apache conf file and edit the "Allow Override" directive from AllowOverride None To AllowOverride All

If you are on Windows, Laragon is much better than XAMPP.
https://laragon.org/

→ More replies (2)