Search code examples
ruby-on-railsapachewordpress.htaccess

How do I edit .htaccess to allow both rails and wordpress requests?


I want to run an instance of wordpress within my rails app. I currently have wordpress files housed in public/wordpress, but I need to configure my .htaccess file to allow both types of requests. How do I do that? currently, .htaccess is:

General Apache options

AddHandler fcgid-script .fcgi  
RewriteEngine On  
RewriteRule ^$ index.html [QSA]  
RewriteRule ^([^.]+)/!$ $1.html [QSA]  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]  
ErrorDocument 500 "Application error Application failed to start properly"

Solution

  • You should start by adding this to the .htaccess in your public folder:

    RewriteCond %{REQUEST_URI} ^/wordpress.*
    RewriteRule .* - [L]
    

    However, this is not the whole story. You also need to edit /etc/apache2/sites-available/ with this addition (to tell Rails not to process anything in /blog as part of the app):

    <Location /wordpress>  
    PassengerEnabled off
    

    Also in /etc/apache2/apache2.conf you may need to tell Apache to make any directory index (e.g. wordpress/) execute an index.php file if there is one:

    DirectoryIndex index.php