Heroku PHP Cedar Stack: Can I Rewrite a URL?

I am running a PHP application on the stack of Heroku cedar. Is there a way to configure URL rewriting rules? I was hoping to do this in .htaccess files, but only access control directives are recognized in this.

I see that Ruby advises using reke rewrite, but what should happen for a PHP application, do you have a URL rewrite setting on Heroku?

+4
source share
2 answers

You can use a regular .htaccess file from PHP to Heroku. Just create a .htaccess file with rewriting conditions similar to this:

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

This example is taken from WordPress. I believe all URLs are now redirected to /index.php . Example here: https://github.com/catsby/php-heroku-htaccess and application here: http://php-heroku-htaccess.herokuapp.com/something

+7
source

To partially answer my own question and continue on what I mentioned in the comments, here is the difference between the Mac and the herohu.htaccess file I need to do:

 RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ $1/$2?arg=$3 #Mac RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ $1/$2.php?arg=$3 #heroku 

This is more a workaround than a solution. I believe that the versions of Apache are different from each other, but in the end I just gave up, debugging it further and use the .htaccess file with two sections in it, which I comment / uncomment.

0
source

All Articles