简体   繁体   中英

How to configure permalinks (.htaccess) for Wordpress in subdirectory

The problem: I can't create friendly permalinks using Wordpress.

We are running Apache. I am attempting to modify .htaccess, but with no success.

Here is the original content of my .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

I found a guy with a similar problem, but for him the /blog was in a nested subdirectory. See this post

Here is his solution:

<VirtualHost *:80>
    DocumentRoot /home/user/
    ServerName mydomain.com
    ServerAlias www.mydomain.com

    <Directory "/home/user">
      Options FollowSymLinks
      AllowOverride none
      Order allow,deny
      Allow from all
    </Directory>

    <Directory "/home/user/blog">
      RewriteEngine On
      RewriteBase /blog/
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . index.php [L]

      Options FollowSymLinks
      Order allow,deny
      Allow from all
    </Directory>
</VirtualHost>

I think my answer is in his solution, but I can't figure out how to modify this snippet for my particular case. My Wordpress is in the domain.com/blog directory.

You must say to the Host, that other files (like .htaccess ) is allowed to override rules.

Virtual Host

<VirtualHost *:80>
    DocumentRoot /home/user/
    ServerName mydomain.com
    ServerAlias www.mydomain.com

    <Directory "/home/user">
      Options FollowSymLinks
      AllowOverride none
      Order allow,deny
      Allow from all
    </Directory>

    <Directory "/home/user/blog">
      Options FollowSymLinks
      ## ADD THESE!
      AllowOverride All
      Order allow,deny
      Allow from all
    </Directory>
</VirtualHost>

Otherwise you can remove your complete blog-directives ( <Directory "/home/user/blog"> ) and set the AllowOverride none to AllowOverride All :

<VirtualHost *:80>
    DocumentRoot /home/user/
    ServerName mydomain.com
    ServerAlias www.mydomain.com

    <Directory "/home/user">
      Options FollowSymLinks
      # Change this!
      AllowOverride All
      Order allow,deny
      Allow from all
    </Directory>
</VirtualHost>

Than you can work with your rewriting on your .htaccess ( /home/user/blog/.htaccess ):

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
</IfModule>

Here, a little example from my site:

<VirtualHost *:80>
    ServerAdmin support@adi-code.de
    ServerName adi-code.de
    ServerAlias adi-code.de www.adi-code.de *.adi-code.de
    DocumentRoot /opt/adi

    <Directory /opt/adi/>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ErrorLog /var/log/apache2/adicode_error.log
    LogLevel warn
    CustomLog /var/log/apache2/adicode_access.log combined
</VirtualHost>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM