Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何启用干净的url?(VPS-Debian 9)_Php_Linux_Url_Debian_Vps - Fatal编程技术网

Php 如何启用干净的url?(VPS-Debian 9)

Php 如何启用干净的url?(VPS-Debian 9),php,linux,url,debian,vps,Php,Linux,Url,Debian,Vps,我有一个VPS服务器(Debian9),我想有一个干净的url 如果输入例如“examle.com/example”,将弹出一个错误“Internal Server error”,而不是显示页面 我需要做些什么才能让这个错误消失并显示页面?试试这个我希望它能帮助你 在html文件夹中创建一个.htaccess文件,并在其中编写blow代码 <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILEN

我有一个VPS服务器(Debian9),我想有一个干净的url

如果输入例如“examle.com/example”,将弹出一个错误“Internal Server error”,而不是显示页面


我需要做些什么才能让这个错误消失并显示页面?

试试这个我希望它能帮助你 在html文件夹中创建一个.htaccess文件,并在其中编写blow代码

<IfModule mod_rewrite.c>
RewriteEngine On    
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
</IfModule>

重新启动发动机
RewriteCond%{REQUEST_FILENAME}.php-f
重写规则!*\。php$%{REQUEST_FILENAME}.php[QSA,L]
或者试试下面

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>

重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写规则^([^\.]+)$$1.php[NC,L]
最后一个是尾部斜杠。(仅根据需要使用代码)


重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写规则^([^/]+)/$$1.php
重写规则^([^/]+)/([^/]+)/$/$1/$2.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_URI}!(\[a-zA-Z0-9]{1,5}|/)$
重写规则(.*)$/$1/[R=301,L]

谢谢。

这种类型的URL(domain.tld/resource/path)需要通过mod_rewrite(使用Apache)或使用Nginx的try_文件配置来处理。当然,您使用哪一个取决于您正在运行的HTTP服务器。除非您明确地安装了Nginx,否则它可能是Apache

假设正在使用Apache(httpd),最简单的管理方法是通过文档根目录(index.php文件所在的位置)中的.htaccess文件。您需要验证您的httpd配置中是否启用了mod_rewrite(通常位于/etc/httpd/httpd.conf或在子目录中进一步细分)

通过mod_rewrite,您可以使用许多配置选项。下面是一个将所有不指向实际目录或文件的URL(从而保留直接从httpd提供静态内容的能力)转换为index.php的示例:

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

重新启动发动机
重写基/
重写规则^index.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]

您需要解析URL以确定如何处理它(它将包含在$\u SERVER['REQUEST\u URI']中。如果需要更改此配置,请务必参考文档。

我不知道为什么,但它始终显示错误“500”,即使我有空的.htaccess和基本文件apache2.conf和000 default.conf

也可以使用.htaccess创建漂亮的url。你能写这段代码吗?我在很多页面上添加了他们写的代码,但一直都显示出这个错误。试试这个,我希望这对你有所帮助。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>