Search code examples
wordpresspermalinksabsolute-pathbitnami

Wordpress is cut off when linking to pages using /index.php/page-name


I have posted this question on bitnami answers as well but I am refining it here. The relevant link is:

I am running the bitnami wordpress stack on my Kubuntu Linux machine. I am linking to pages internal to my site in my content with absolute links like this /index.php/page-name and my server is running at http://127.0.1.1/wordpress/. The appropriate relative links work correctly but the absolute links do not.

The behaviour I am getting with the absolute links is that the /wordpress/ path component is truncated when using /index.php/page-name and points to http://127.0.1.1/index.php/page-name instead of http://127.0.1.1/wordpress/index.php/page-name.

I am using the Post name permalink structure and my .htaccess file also has the following rewrite rules:

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

# END WordPress

Every time I click the link I get a 404 error with this message in the apache error log:

script '/home/nandu/wordpress-3.3.1-1/apache2/htdocs/index.php' not found or unable to stat

I am not sure why the wordpress part of the URL is getting cut off when my settings in the admin area show both the site url and address url pointing to http://127.0.1.1/wordpress.

Furthermore according to the wordpress codex /index.php/ should point to the site root.

I am at my wits end as far as this problem is concerned. Kindly do let me know if you require any more information.

Thanks in advance. nav


Solution

  • I have succeeded in getting my bitnami wordpress stack to run wordpress on the root url http://127.0.1.1/ so that the links in my content will work identically to my production system.

    Here are the steps I followed modify to suit your needs:

    1. Edit the following lines in /<INSTALL_DIR>/apache2/conf/httpd.conf

      from:

      DocumentRoot "/<INSTALL_DIR>/apache2/htdocs"

      to

      DocumentRoot "/<INSTALL_DIR>/apps/wordpress/htdocs"

    2. In the same file, also change the following directive

      from

      <Directory "/<INSTALL_DIR>/apache2/htdocs">

      to

      <Directory "/<INSTALL_DIR>/apps/wordpress/htdocs">

    3. Go to /<INSTALL_DIR>/apps/wordpress/conf/wordpress.conf and comment out the following lines by prepending a #:

      Alias /wordpress/ "/<INSTALL_DIR>/apps/wordpress/htdocs/"

      Alias /wordpress "/<INSTALL_DIR>/apps/wordpress/htdocs"

    4. In the same file change

      from:

      RewriteBase /wordpress/

      to

      RewriteBase /

    5. In the same file, uncomment the following lines by removing the #:

      #RewriteEngine On

      #RewriteRule ^/$ /wordpress/ [PT]

    6. Restart the bitnami apache server:

      /<INSTALL_DIR>/ctlscript restart

    7. Edit the following lines in /<INSTALL_DIR>/apps/wordpress/htdocs/.htaccess

      from:

      RewriteBase /wordpress/

      to

      RewriteBase /

      and

      RewriteRule . /wordpress/index.php [L]

      to

      RewriteRule . /index.php [L]

    8. Login to PHPMyAdmin at http://127.0.1.1/phpmyadmin and go to the wp_options table change siteurl value

      from:

      http://127.0.1.1/wordpress

      to

      http://127.0.1.1

    9. After this rename the index.html file in the /<INSTALL_DIR>/apache2/htdocs/ directory to old-index.html

    10. Restart the bitnami apache server:

      /<INSTALL_DIR>/ctlscript restart

    Navigating to http://127.0.1.1/ should show the homepage of the site. There is some documentation on the bitnami wordpress docs about what needs to be done to change the root url but they seemed incomplete in terms of what I had to do to accomplish this.

    Hope that helps someone. :-) nav