You and WordPress work together in glorious harmony to create the .htaccess
file that lets you use a pretty-permalink structure in your site.
To create the .htaccess file, you need to be comfortable uploading files via SFTP
and changing permissions. Turn to Book 2, Chapter 2 if you’re unfamiliar with
either of those tasks.
If .htaccess already exists, you can find it in the root of your directory on your
web server — that is, the same directory where you find your wp-config.php file.
If you don’t see it in the root directory, try changing the options of your SFTP
client to show hidden files. (Because the .htaccess file starts with a period [.],
it may not be visible until you configure your SFTP client to show hidden files.)
If you don’t already have an .htaccess file on your web server, follow these
steps to create an .htaccess file on your web server and create a new permalink
structure:
- 1. Using a plain-text editor (such as Notepad for Windows or TextEdit for a Mac), create a blank file; name it htaccess.txt and upload it to your web server via SFTP.
- 2. After the file is uploaded to your web server, rename the file .htaccess (notice the period at the beginning), and make sure that it’s writable by the server by changing permissions to 755 or 777.
- 3. Create the permalink structure on the Customize Permalink Structure page of your WordPress Dashboard.
- 4. Click the Save Changes button at the bottom of the Customize Permalink Structure page.
WordPress inserts into the .htaccess file the specific rules necessary for
making the permalink structure functional on your site.
If you follow the preceding steps correctly, you have an .htaccess file on your
web server with the correct permissions set so that WordPress can write the correct rules to it. Your pretty-permalink structure works flawlessly. Kudos!
If you open the .htaccess file and look at it now, you see that it’s no longer blank.
It should have a set of code in it called rewrite rules, which looks something like
this:
# BEGIN WordPress<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule># END WordPress
I could delve deeply into .htaccess and all the things you can do with this file, but
I’m restricting this chapter to how it applies to WordPress permalink structures. If
you want to unlock more mysteries about .htaccess, check out “Comprehensive
Guide to .htaccess” at www.javascriptkit.com/howto/htaccess.shtml.
WORKING WITH SERVERS THAT DON’T USE
APACHE MOD_REWRITE
Using permalink structures requires your web hosting provider to have a specific
Apache module option called mod_rewrite activated on its servers. If your web hosting
provider doesn’t have this item activated on its servers, or if you’re hosting your site on
a Windows server, the custom permalinks work only if you type index.php in front of
any custom permalink tags.
Create the custom permalink tags like this:
/index.php/%year%/%month%/%date%/%postname%/
This format creates a permalink like this:
https://yourdomain.com/index.php/2019/01/01/wordpress-all-in-onefor-dummies
You don’t need an .htaccess file to use this permalink structure
ليست هناك تعليقات:
إرسال تعليق