/
/
SEO education
/
htaccess file - what it should look like, wordpress rules

htaccess file - what it should look like, wordpress rules

htaccess file - what it should look like, wordpress rules

The .htaccess file is a very specific element of the server. Its uniqueness is already marked in its name, which unusually begins with a period. The very name of the file is an abbreviation for Hypertext Access. This file allows you to configure and modify many elements of the server.

.htaccess file how should it look like ?

Learn what the htaccess file looks like, where it is on the server, how to edit it. Learn about creating the file and its basic redirects.

plik htaccess konfiguracja
htaccess file properly executed

The .htaccess file is the base setting of a program, in the case of the server in question, which is used to change its behavior. It works in the directory where it will be placed and in all subdirectories. If any subdirectory is to be defined differently then a separate file must be created for it. There can be many such files, and each of them can define a completely different action.

In practice, it may be that each directory has a separate .htaccess file.

htaccess file - creation, how to edit ?

The file allows you to add or change existing directives. Each function is a line of text or code. It tells the server how to behave. So you can add or change code in .htaccess to change the server's functions.

File modifications - enter command

Its essential element is the [enter] character at the end of each line of text or code. Therefore, when modifying a file, remember to enter, after each command, the [enter] character at the end of the line.

konfiguracja pliku htaccess wordpress
htaccess file creation and editing

.htaccess file in wordpress - what is it for

That is, htaccess rewriter for wordpress.

The list of functions that can be implemented with it is extensive, such as securing a page with a password, creating a custom error page or performing a 301 redirect to another website. What else can be done with its help?

  • resource access control - if a directory is to be hidden, this can be done with a .htaccess file. After its preparation, it is published on the FTP server in that directory to be hidden;
  • restrict access - the password protection mentioned earlier - you can restrict access to the directory or the entire website;
  • allows you to define the start page - the default start files are index.php or index.html;
  • defining the listing settings of any directory - this is especially useful when there are many documents to be downloaded on the site, and the site developer wants to avoid having to create an HTML document each time;
  • Banning by IP address - an unwanted user can always appear. Instead of agonizing with him and monitoring his destructive activity on the site, you can block him right "on entry";
  • Address rewriting - this is an extremely useful and useful feature. It allows you to replace overly long and impractical addresses with more friendly and easier to remember ones;

How to open an .htaccess file?

The basic issue is to use a suitable text editor. Notepad is best, as it does not add any custom formatting. Open Office or Word can make the prepared file not work.

In some cases, the hosting provider provides a special text editor to modify the files in this particular .htaccess. Why does this matter? Such an editor does not impose its own formatting, so it will be interpreted correctly, and you can see the changes on the page.

When doing so, you need to remember to use [enter] at the end of each line. Additional comments are posted with a hashtag (#). The last line of the file must be left blank.

After preparing the file, you need to upload it to the server. This should be done with an FTP client that displays hidden files, because that is the nature of .htaccess. FTP clients include Filezilla, WinSCP, or TotalCommander.

czym otworzyc htaccess
htaccess file redirects

.htaccess file and SEO

It has been known for a long time that correct and impressive coding of the site is not enough. You still need to take care of SEO. Interestingly, the .htaccess file can help a lot with this. Several features that can be coded in it can significantly improve the rating of the site by robots and users, and thus the site will improve ranking and be positioned higher.

301 redirects using htaccess

One of the primary uses of .htaccess is to perform a 301 redirect. It so happens that a site undergoes a redesign. Some subpages are eliminated, others are added, still others are changed or modified. If it is a site with a history, the deleted pages may already be indexed in Google search. In order not to lose the earned position, you can perform a 301 redirect on file. The result? A user who hits a non-existent page in a search engine will automatically be redirected to another page - chosen by the administrator. He will not meet the wall and will find the information he needs. Robots that analyze indexed links won't hit a blank either.

The commands to be entered in the file are:

RewriteCond %{REQUEST_URI} ^/strona-1 [OR]
RewriteCond %{REQUEST_URI} ^/strona-2 [NC]
RewriteRule ^(.*)$ http://domena.com/strona-3 [R=301,L]

przekierowania 301 w pliku htaccess
301 in htaccess how to execute correctly

Error page 404

Error 404 appears very often for various reasons. You can find more about it in a dedicated article. Unless the site administrator decides otherwise, a default page will be displayed to inform the user about the error. However, you can design your own and force its display. A user who hits a personalized 404 error page won't be so quick to give up visiting the site he's looking for. See common website errors to watch out for.

Include in the htaccess file:

# for error 404

ErrorDocument 404 /blad404.html

przyklady konfiguracji pliku i 404
crash page error 404

Failure page

Websites sometimes require an extended shutdown due to ongoing administrative work, for example: with the Wordpress care service you can ensure uninterrupted website operation.

Unexpected work or errors cause users to have trouble viewing content and no information about the reasons. You can design your own crash page, which, for example, will count down the time until the site restarts. This will provide comprehensive information to users and prevent them from being negative about the situation.

The command to be entered then is:

DirectoryIndex failure.html

Duplicate content on subpages

If the page displays with www and without www, then for the robots it may be duplicate content and they will start to severely underestimate the position. It is worth avoiding this. You can leave all the pages called up, but make a redirect in the .htaccess file. This way the robots will also follow the redirect, one version of the page will be displayed, and the rating of the site will go up.

Redirection to the World Wide Web


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^strona.pl [nc]
RewriteRule ^(.*)$ http://www.strona.pl/$1 [r=301,nc]

#Przekierowanie na bezWWW
RewriteCond %{HTTP_HOST} ^www.strona.pl$ [NC]
RewriteRule ^(.*)$ http://strona.pl/$1 [R=301,L]

Friendly website links

As mentioned, .htaccess also allows you to shorten links that are too long and unintuitive to short and easy to remember. Such an action has a very positive effect on seo. Robots like short, simple and informative links. See what simple url addresses are.

‍ How to do it?

# we initiate rewrite engine
RewriteEngine on
# for an example from www.strona.pl/strona/costamdalej/
RewriteRule ^strona/([^/.]+)/?$ index.php?strona=$1 [L]
# for instance from www.strona.pl/costamdalej/
RewriteRule ^/([^/.]+)/?$ index.php?strona=$1 [L]

In this way, the link is shortened, and the reference still refers to its original form.

jak ustawic przyjazne linki i adresy url
How to set simple addresses in htaccess ?

Increase website speed

If a website loads too slowly and takes too long to load, the cause may be data overload, which can be compressed. By entering the appropriate commands into the .htaccess file, you can achieve significant data compression without any loss. The loading speed of the page will increase. This will affect its rating by robots and users.

The command that is used to force compression is:

mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

As you can see, the .htaccess file allows you to implement various practical functionalities on the site (blocking access, restricting access, blocking users), as well as being important in supporting various seo activities for the site. Using a few strategic commands, you can achieve a lot and improve the user's experience with the site.

How to improve the technical parameters of the site on Wordpress ?

Usually in order to improve performance it is enough to optimize the wordpress site or appropriate optimization of images in wordpress.Comprehensive optimization work is also worthwhile to optimize the wordpress database.

Perform 410 redirection - remove subpages from the index

Tidying up the SERPs (search results for url's within a domain, checking as sile:domain.co.uk)

The htaccess file also allows you to deliberately deplete a website of old or non-existent subpages that you want to remove from Google's index. This redirection usually needs a few days.‍

Generator htaccess

If all the intricacies of configuring an htaccess file are too difficult for you, you can use ready-made rules or generate your file with automation.

  • https://www.htaccessredirect.net
  • https://pl.rakko.tools/tools/28/

Common problems of html and php files in wordpress?

It's always worth checking if you don't have an html file on ftp that may have a higher priority and it will be the one that will run instead of your wordpress index.php file. What to do then ? Remove the index.html file from the server or rename it to index_bak.