apache2使用.php添加所有网址

时间:2018-10-08 11:09:32

标签: php url-rewriting apache2

我正在运行Ubuntu 18.04服务器,而php版本是5.6

https://myurl its index.php在点击其他链接时自动加载

https://myurl/deam不能用php自动填充

  

https://myurl/dream.php enter image description here   我通过ht访问做了一些事情,但不知道哪个代码阻止了我的ht访问code

当我现在用.php键入其工作时,我想要每当链接单击.php时自动填充它,我该怎么做?

2 个答案:

答案 0 :(得分:1)

您可以将.htaccess与重写一起使用

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteCond %{REQUEST_FILENAME}\.php ^(.*)\.php(.*)$
RewriteRule .* %1.php?%2 [QSA]

答案 1 :(得分:0)

https://serverfault.com/a/531587
下次尝试所有答案对您有帮助

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## don't touch /forum URIs
RewriteRule ^forums/ - [L,NC]

## hide .php extension snippet

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]