skip to Main Content

I have an issue with creating a rewrite rule.

We have a WordPress install and we need to server a mix of static and dynamic content.

Say we have a page in wordpress of /support, it’s the landing page for forums, documentation etc.

Our documentation is generated outside of wordpress and we’d like it to be served from /support/documentation.

How would we ho about this? I’ve tried a few options the closest being adding the documentation in a seperate folder:

RewriteRule ^support/documentation(/.*)?$ /support-4-0/Documentation$1 [NC,L]

The trouble here is that the support-4-0 folder is still served by Apache leading to issues with duplicated content. Is there a better way to go abut this?

3

Answers


  1. If you do not have a problem with storing the support-4-0 folder in a location other than your site’s DocumentRoot folder, you can use the Alias feature.

    From Apache Documentation:

    The Alias directive are used to map between URLs and filesystem paths. This allows for content which is not directly under the DocumentRoot served as part of the web document tree.

    <VirtualHost *:80>
    
        DocumentRoot /var/www/domain.com/public_html
    
        # ...
    
        Alias /support/documentation /var/www/domain.com/support-4-0
    
        <Directory /var/www/domain.com/documentation>
            Options MultiViews Indexes Includes FollowSymLinks ExecCGI
            AllowOverride All
            Require all granted
            allow from all
        </Directory>
    
       # ...
    
    </VirtualHost>
    

    Alias syntax:

    Alias "Map-This-URI" "To-This-System-Path"
    

    You need to specify additional sections which cover the destination of aliases. This is example directory config:

    <Directory "Specified-System-Path">
        Options MultiViews Indexes Includes FollowSymLinks ExecCGI
        AllowOverride All
        Require all granted
        allow from all
    </Directory>
    

    PS: Reference directory tree for above configuration :

    /
    └─ var
       └─ www
          └─ domain.com
             ├─ public_html
             └─ support-4-0
    
    Login or Signup to reply.
  2. If you want to stop user to access support-4-0 you can redirect your user from that page to your new support page which starts from support.

    You can use below,

    RewriteRule ^support-4-0/(.*) http://websitename/support/$1 [R]
    
    Login or Signup to reply.
  3. Make sure the apache mod_rewrite module is installed. Then, use something like this in your apache config, virtual host config, or (less desirable) .htaccess file:

      RewriteEngine On
    RewriteRule ^/(.*)$   /pages/$1
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search