最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

apache - WordPress Permalinks still not working despite all necessary settings

programmeradmin5浏览0评论

I apologize for the seemingly duplicate issue posting but I can't seem to find someone who has come across my specific issue and resolved it. This post got close but I did everything they did.

here's where I'm at:

  • migrated a wp site to an AWS server running ubuntu 18
  • rewrite mod is enabled
  • site is in /home/ubuntu/sites/my-wp-site
  • site dir is owned by www-data
  • site's virtual hosts file has the necessary "Directory" section with "AllowOverride All" set
  • site's .htaccess file has the rewrite rules set by the permalinks settings in the UI
  • apache2 config also has the "AllowOverride All" set for a "Directory" section pointed at /home/ubuntu/sites

What am I missing?

.htaccess

contents after setting the permalinks to date and time (empty otherwise)

 BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType image/jpg "access plus 1 year"
        ExpiresByType image/jpeg "access plus 1 year"
        ExpiresByType image/gif "access plus 1 year"
        ExpiresByType image/png "access plus 1 year"
        ExpiresByType text/css "access plus 1 month"
        ExpiresByType application/pdf "access plus 1 month"
        ExpiresByType text/javascript "access plus 1 month"
        ExpiresByType text/html "access plus 5 minutes"
        ExpiresByType image/x-icon "access plus 1 year"
        ExpiresDefault "access plus 6 hours"
</IfModule>
<ifModule mod_headers.c>
Header set X-Endurance-Cache-Level "2"
</ifModule>
Options -Indexes

                                <IfModule mod_rewrite.c>
                                        RewriteEngine On
                                        RewriteBase /
                                        RewriteRule ^/wp-content/endurance-page-cache/ - [L]
                                        RewriteCond %{REQUEST_METHOD} !POST
                                        RewriteCond %{QUERY_STRING} !.*=.*
                                        RewriteCond %{HTTP_COOKIE} !(wordpress_test_cookie|comment_author|wp\-postpass|wordpress_logg$
                                        RewriteCond %{DOCUMENT_ROOT}/wp-content/endurance-page-cache/$1/_index.html -f
                                        RewriteRule ^(.*)$ /wp-content/endurance-page-cache/$1/_index.html [L]
                                </IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

apache2.conf

...
<Directory /home/ubuntu/sites/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>
...

vhost for site

...
DocumentRoot /home/ubuntu/sites/my-wp-site
...
<Directory /home/ubuntu/sites/my-wp-site>
     Options Indexes FollowSymLinks
     AllowOverride All
     Require all granted
</Directory>
...

I apologize for the seemingly duplicate issue posting but I can't seem to find someone who has come across my specific issue and resolved it. This post got close but I did everything they did.

here's where I'm at:

  • migrated a wp site to an AWS server running ubuntu 18
  • rewrite mod is enabled
  • site is in /home/ubuntu/sites/my-wp-site
  • site dir is owned by www-data
  • site's virtual hosts file has the necessary "Directory" section with "AllowOverride All" set
  • site's .htaccess file has the rewrite rules set by the permalinks settings in the UI
  • apache2 config also has the "AllowOverride All" set for a "Directory" section pointed at /home/ubuntu/sites

What am I missing?

.htaccess

contents after setting the permalinks to date and time (empty otherwise)

 BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType image/jpg "access plus 1 year"
        ExpiresByType image/jpeg "access plus 1 year"
        ExpiresByType image/gif "access plus 1 year"
        ExpiresByType image/png "access plus 1 year"
        ExpiresByType text/css "access plus 1 month"
        ExpiresByType application/pdf "access plus 1 month"
        ExpiresByType text/javascript "access plus 1 month"
        ExpiresByType text/html "access plus 5 minutes"
        ExpiresByType image/x-icon "access plus 1 year"
        ExpiresDefault "access plus 6 hours"
</IfModule>
<ifModule mod_headers.c>
Header set X-Endurance-Cache-Level "2"
</ifModule>
Options -Indexes

                                <IfModule mod_rewrite.c>
                                        RewriteEngine On
                                        RewriteBase /
                                        RewriteRule ^/wp-content/endurance-page-cache/ - [L]
                                        RewriteCond %{REQUEST_METHOD} !POST
                                        RewriteCond %{QUERY_STRING} !.*=.*
                                        RewriteCond %{HTTP_COOKIE} !(wordpress_test_cookie|comment_author|wp\-postpass|wordpress_logg$
                                        RewriteCond %{DOCUMENT_ROOT}/wp-content/endurance-page-cache/$1/_index.html -f
                                        RewriteRule ^(.*)$ /wp-content/endurance-page-cache/$1/_index.html [L]
                                </IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

apache2.conf

...
<Directory /home/ubuntu/sites/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>
...

vhost for site

...
DocumentRoot /home/ubuntu/sites/my-wp-site
...
<Directory /home/ubuntu/sites/my-wp-site>
     Options Indexes FollowSymLinks
     AllowOverride All
     Require all granted
</Directory>
...
Share Improve this question edited Sep 21, 2020 at 15:31 fischgeek asked Sep 21, 2020 at 1:39 fischgeekfischgeek 1214 bronze badges 7
  • What is the DocumentRoot? When you say the vHost has the necessary Directory section, can you confirm the file system path this is set for. Please include the contents of your .htaccess file and where exactly this is located. If you add some nonsense to your .htaccess file, does it “break”? – MrWhite Commented Sep 21, 2020 at 10:06
  • The site is working fine so the vhost settings are accurate. The directory is pointed at the site (/home/ubunut/sites/mywpsite). I've updated the question with the .htaccess. – fischgeek Commented Sep 21, 2020 at 12:13
  • "The site is working fine so the vhost settings are accurate." - but how can you be sure; permalinks aren't working? There is a syntax error on one of your _CondPattern_s here: |wordpress_logg$ - which implies either mod_rewrite is not enabled or .htaccess overrides are not enabled (otherwise you'd be getting a 500 response). – MrWhite Commented Sep 21, 2020 at 13:03
  • @MrWhite - If the directory root is inaccurately entered in the vhost, then even the front page wouldn't render. Correct? mod_rewrite is enabled and confirmed by the console when I try to enable it. The typo in the .htaccess is a mystery considering I didn't put any of that in there manually. It was generated by selecting the radio button in the Permalinks settings. – fischgeek Commented Sep 21, 2020 at 14:00
  • "If the directory root is inaccurately entered in the vhost, then even the front page wouldn't render. Correct?" - Not necessarily, there's insufficient info in the question. If your DocumentRoot is set to /home/ubuntu/sites, but are accessing your site as example/my-wp-site/ then the "front page" would render correctly but permalinks would not. However, the "syntax error" I mentioned above is a show-stopper and suggests your vHost/server config is indeed misconfigured (as stated). – MrWhite Commented Sep 21, 2020 at 15:03
 |  Show 2 more comments

1 Answer 1

Reset to default 1

Since the domain/site has an ssl, the vhosts file for the ssl is separate and also needs to be updated. Not just the normal port 80 entry.

vhost (:80)

my-wp-site.conf

<VirtualHost *:80>
...
DocumentRoot /home/ubuntu/sites/my-wp-site
...
<Directory /home/ubuntu/sites/my-wp-site>
     Options Indexes FollowSymLinks
     AllowOverride All
     Require all granted
</Directory>
...
</VirtualHost>

vhost (:443)

my-wp-site-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ...
    ServerName my-wp-site
    ServerAlias my-wp-site
    DocumentRoot /home/ubuntu/sites/my-wp-site
    <Directory /home/ubuntu/sites/my-wp-site>
        Options None FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    ...
</VirtualHost>
</IfModule>
发布评论

评论列表(0)

  1. 暂无评论