Welcome Demo
Setting up .htaccess
files to work on Windows, Debian, and openSUSE systems with Apache.
On Windows, you'll need to install Apache (typically through WAMP, XAMPP, or a manual setup) to support .htaccess
files.
Enable .htaccess
in Apache Configuration:
C:\wamp64\bin\apache\apache2.x.x\conf\httpd.conf
or C:\xampp\apache\conf\httpd.conf
.AllowOverride None
to AllowOverride All
:<Directory "C:/wamp64/www/">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Ensure mod_rewrite
is enabled:
httpd.conf
file and make sure it's not commented out (remove the #
if present):LoadModule rewrite_module modules/mod_rewrite.so
Restart Apache:
Create or Edit .htaccess
File:
.htaccess
file in the root directory of your website (C:\wamp64\www\your_project
or equivalent).On Debian, Apache typically needs a few steps to fully support .htaccess
files.
Enable .htaccess
in Apache Configuration:
/etc/apache2/sites-available/000-default.conf
.<VirtualHost>
block, change AllowOverride None
to AllowOverride All
for the directory you want to use:<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Enable mod_rewrite
:
sudo a2enmod rewrite
sudo systemctl restart apache2
Create or Edit .htaccess
File:
.htaccess
file in the appropriate web directory (e.g., /var/www/html/
).For openSUSE, the steps are similar to Debian, with some specific differences in file locations.
Enable .htaccess
in Apache Configuration:
/etc/apache2/default-server.conf
.<Directory "/srv/www/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Enable mod_rewrite
:
mod_rewrite
module and restart Apache:sudo a2enmod rewrite
sudo systemctl restart apache2
Create or Edit .htaccess
File:
.htaccess
file in the web directory, typically /srv/www/htdocs
..htaccess
Configurations:Here are some typical rules you might want to use in your .htaccess
file:
Rewrite URLs:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
Redirects:
Redirect 301 /old-page.html /new-page.html
Custom Error Pages:
ErrorDocument 404 /404.html
.htaccess
FileTo test if your .htaccess
is working, add a simple redirect to it:
Redirect 301 /test-page.html /index.html
Then, create a test-page.html
in your directory. If visiting your-domain/test-page.html
redirects to your home page, your .htaccess
is working correctly.