0

I'm simply trying to replace

products/t-210.php

In my web browser with

products/t210

(for readability) by making a soft link t210->t-210.php

In my virtual hosts I have

 <Directory /var/www/xxxxxxx.com/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
    Require all granted
    </Directory>

I get no errors in apache2 error.log
access.log generates code 200 (delivered)

In the HTML output I can see that the PHP is not being executed.
The web server is simply delivering the link/PHP file as text (obviously the PHP file works)

I searched and read for hours.

What am I missing here?

ADDITION

If I run php t210 on command line then this DOES generate the correct output
It only fails when I "ask" Apache to do it...
So I'm not about the .htaccess file - I'm after why Apache is failing?

blakeyman
  • 1
  • 2
  • Do you have a `.htaccess` file in the project's public folder? If so, what is in it? – Jeremy Harris Feb 04 '19 at 17:32
  • I have no .htaccess file – blakeyman Feb 04 '19 at 17:34
  • You need an htaccess with mod_rewrite rules for how to rewrite the url. Search SO and you will find tons of help with this same issue. – Jeremy Harris Feb 04 '19 at 17:36
  • @JeremyHarris so one *can't* use a symlink in this way then? – blakeyman Feb 04 '19 at 17:39
  • You want to look into url rewrite with htaccess. Also, for things like dropping dash just name your file better. Symlinks a linux os function and unless you want to get into the business of keeping this updated I would not recommend this use. – nerdlyist Feb 04 '19 at 17:41
  • Check out this article https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/ – nerdlyist Feb 04 '19 at 17:43
  • https://stackoverflow.com/q/25080835/468592 – Jeremy Harris Feb 04 '19 at 18:01
  • @nerdlyist Thank you.I tried the recommended solution but got a 404 error – blakeyman Feb 04 '19 at 18:01
  • Can you be a little more specific on what you tried? I did not give an exact solution just general pointers. – nerdlyist Feb 04 '19 at 20:40
  • @nerdyist the article you posted about removing .php or .html – blakeyman Feb 05 '19 at 08:29
  • To remove the .php extension from a PHP file for example yoursite.com/wallpaper.php to yoursite.com/wallpaper you have to add the following code inside the .htaccess file: `RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L]` – blakeyman Feb 05 '19 at 08:29
  • Apache recognizes the type of the file based on its name. By default if file ends with php its content is interpreted by php and output is sent to the client. In constrast if file ends with jpg the php is not involved. The usual way of changing the shape of urls is to use rewriting. It means you keep .php extension for files and you hide it at the url rewriting step. – Dzienny Feb 05 '19 at 08:53
  • @Dzienny OK - now I get "why" - thanks ;) – blakeyman Feb 05 '19 at 09:12
  • @nerdlyist : removing the `MultiViews` from the setting in virtual hosts conf file made the .htaccess solution in the link you posted work. Many thanks. I understand and now have "pretty" URLs – blakeyman Feb 05 '19 at 09:42

0 Answers0