Create new htaccess file wordpress
Here is an example of a basic .htaccess
file for a WordPress website:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Rewrite rules for WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule. /index.php [L]
</IfModule>
# END WordPress
Let me explain what each line does:
# BEGIN WordPress
and# END WordPress
are comments that mark the beginning and end of the WordPress-specific configuration.<IfModule mod_rewrite.c>
checks if the Apache modulemod_rewrite
is available. If it is, the code inside the block will be executed.RewriteEngine On
enables the rewrite engine.RewriteBase /
sets the base URL for the rewrite rules.RewriteRule ^index\.php$ - [L]
tells Apache to skip rewriting the URL if it matches theindex.php
file.RewriteCond %{REQUEST_FILENAME}!-f
checks if the requested file does not exist.RewriteRule. /index.php [L]
tells Apache to rewrite the URL toindex.php
if the requested file does not exist.
You can add more rules to this file to customize the behavior of your WordPress website. For example, you can add rules to:
- Redirect URLs:
RewriteRule ^old-url$ /new-url [R=301,L]
- Block access to certain files or directories:
RewriteRule ^secret-file$ - [F,L]
- Set custom headers:
RewriteRule. - [E=HTTP_X_CUSTOM_HEADER:value]
Remember to save the file with the correct name (htaccess
or .htaccess
) and upload it to the root directory of your WordPress website.
If you're using a WordPress plugin like Yoast SEO or All in One SEO Pack, they may have their own .htaccess
files that you should merge with this one.