简体   繁体   English

通过Mod_Rewrite的无扩展PHP文件

[英]Extensionless PHP File via Mod_Rewrite

I am trying to make a PHP file look like a folder via Mod_Rewrite... but I have no idea how to do it. 我试图通过Mod_Rewrite使一个PHP文件看起来像一个文件夹...但是我不知道该怎么做。

I used to do it like this: 我曾经这样做:

    <files store>
    ForceType application/x-httpd-php
    </files>

    DirectoryIndex store

Which was the simplest way to do it... but I changed servers and "ForceType" is not allowed... 这是最简单的方法...但是我更改了服务器,不允许使用“ ForceType” ...

I need to do it with Mod_ReWrite somehow... 我需要用Mod_ReWrite来做...

I only want it to work on the one file not every file that ends in PHP... 我只希望它能在一个文件上工作,而不是每个以PHP结尾的文件...

Any help would be very much appreciated. 任何帮助将不胜感激。

Thank You 谢谢

Try this if u need to append query: 如果您需要附加查询,请尝试以下操作:

RewriteRule ^folder/([^/]+)/([^/]+) /yourfile.php?&id=$1&user=$2  [NC]

OR this when not 或者这不是

RewriteRule ^folder /yourfile.php  [NC]

Use this in your root .htaccess: 在您的根.htaccess中使用此命令:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+(file)\.php[\s?] [NC]
RewriteRule ^ /%1/ [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

Change file.php to whatever your file name is. file.php更改为您的文件名。

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

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