简体   繁体   English

如何正确删除 .PHP?

[英]How to Remove .PHP Correctly?

Ok, So iv'e decided to remove all .php extentions from the url, and for this iv'e used the simple method:好的,所以我决定从 url 中删除所有 .php 扩展名,为此我使用了简单的方法:

Options MultiViews+

However, My profile page now displays almost nothing, with a black background because of the URL.但是,由于 URL 的原因,我的个人资料页面现在几乎不显示任何内容,背景为黑色。 If I input:如果我输入:

profile.php?username=Joe.Bills

It works perfectly fine, If however, I use:它工作得很好,但是,如果我使用:

profile?username=Joe.Bills 

It automatic changes the url and adds a / AFTER profile Example:它会自动更改 url 并添加/ AFTER profile示例:

profile/?username=Joe.Bills

And thus, thinking its in a "separate directory" causes the error.因此,认为它在“单独的目录”中会导致错误。 How can i remove it from adding the additional / so it doesn't think its going to a separate directory我怎样才能从添加额外的/删除它,这样它就不会认为它会进入一个单独的目录

PS My link's are correct and currently is this: PS 我的链接是正确的,目前是这样的:

<a href="profile?username=<?php echo $_SESSION['user_name']; ?>"><span class="bg">Profile</span></a>

Again, as I said, If I put再次,正如我所说,如果我把

profile.php?username=Joe.Bills 

It works completely fine, so I don't understand why the URL thinks its a directory when entered, So my question would be:它工作得很好,所以我不明白为什么 URL 在输入时认为它是一个目录,所以我的问题是:

How can I remove .PHP extensions a different way to fix this, or is there a way I can fix this with what I currently have and how?我怎样才能以不同的方式删除 .PHP 扩展来解决这个问题,或者有什么方法可以用我目前拥有的东西来解决这个问题?

You can use the following instead of Options +Multiviews :您可以使用以下内容代替Options +Multiviews

 RewriteEngine on
 #remove trailing slashes
 RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !/$ %{REQUEST_URI}.php [NC,L]

This will allow you to access .php files without extension/slash at the end.这将允许您访问 .php 文件而没有扩展名/斜线结尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM