Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to optimize the .htaccess of WordPress

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to optimize WordPress.htaccess. Xiao Bian thinks it is quite practical, so share it for everyone to make a reference. Let's follow the editor and have a look.

What is WordPress.htaccess optimization tips?

We all know that page load speed has a very important impact on blog traffic. More and more people are also discussing how page load speed is likely to be an important SEO factor for Google and other search engines.

The main problem with.htaccess files right now is that RewriteCond commandingly checks for the existence of the file on disk, even if it doesn't need to be checked at all, adding to the page load time with each access to disk.()

# WordPress Start RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !- f RewriteCond %{REQUEST_FILENAME} !- d RewriteRule . /index.php [L] # WordPress End

The current WordPress .htaccess is not optimized at all. In a Webmaster World post, Jim Morgan, an expert at Mod_Rewrite/.htaccess, suggested replacing the original file with the following.htaccess file:

# WordPress starts RewriteEngine on # #Unless you have previously set a different RewriteBase #You can delete or uncomment the following code # RewriteBase directive: RewriteBase / # #If this request is for "/" or is already written to WP RewriteCond $1 ^(index\.php)?$ [OR]#or if the request is for an image, css, or js file RewriteCond $1 \. (gif|css| js| ico)$ [NC,OR] #If URL points to an existing file RewriteCond %{REQUEST_FILENAME} -f [OR] #If URL points to an existing directory RewriteCond %{REQUEST_FILENAME} -d #then skip rewriting and go directly to WP RewriteRule ^(.*)$|ico)$ [NC,OR] #如果URL指向存在的文件 RewriteCond %{REQUEST_FILENAME} -f [OR] #如果URL指向了存在的目录 RewriteCond %{REQUEST_FILENAME} -d # 那么跳过重写直接到WP RewriteRule ^(.*)$ - [S=1] #Otherwise point to WP rewrite the request RewriteRule . /index.php [L] # #WordPress End

Here's what happens when you optimize the previous code:

Because the index.php file exists, checking its existence is meaningless, thus avoiding unnecessary file checking when sending requests to example.com, www.example.com, or example. com/index.php. example.com/

Each request for static file access does not actually need to be redirected. If the file does exist on disk, the request will be answered, otherwise the file does not exist or the default subdirectory index.php file should be returned. These static files include.jpg,.png,.gif,.css,.js files and other static files. Since most blogs contain a lot of static files, this can have a significant impact on page load speed.

Thank you for reading! How to optimize WordPress.htaccess is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge. If you think the article is good, you can share it so that more people can see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report