是否为子域删除带有.htaccess的.php扩展名?

是否为子域删除带有.htaccess的.php扩展名?,php,.htaccess,url-rewriting,Php,.htaccess,Url Rewriting,我不擅长url重写 我的域名是helloboy 我的子域是www和labs 我想删除.php扩展仅用于子域实验室和目录图形 发件人: 致: 我该怎么做 这是我的.htaccess代码: RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} ^labs\.helloboy\.com$ /$1.php -f RewriteRule ^(graph/load/.*?)/?$ $1.php [L,NC] 也许这会有帮助: Rewrite

我不擅长url重写

我的域名是
helloboy

我的子域是
www
labs

我想删除.php扩展仅用于子域
实验室
目录图形

发件人:

致:

我该怎么做

这是我的
.htaccess
代码:

 RewriteEngine on
 RewriteBase /
 RewriteCond %{HTTP_HOST} ^labs\.helloboy\.com$ /$1.php -f
 RewriteRule ^(graph/load/.*?)/?$ $1.php [L,NC]
也许这会有帮助:

RewriteCond %{HTTP_HOST}  labs.helloboy.com$ 
RewriteRule ^graph/(.*)/?$ graph/$1.php [L,NC]

我建议您在graph下创建一个文件(或者在任何地方,由您决定),例如
graph/index.php
,它将处理图形重写请求。然后将
show.php
(以及其他要重定向的文件)移动到适合处理内容的不同文件夹,例如在
graph/lib

现在假设下面的一切都是“不存在的”,您只需根据路径处理请求(如)

虚构的文件结构如下所示:

root (in your case it would prolly be www/labs)
-- .htaccess
-- graph
   -- index.php (handles rewrites, can be anywhere you want but it must be reflected in the .htacces file)
   -- lib (location to store the existing files, can be anywhere you want)
      -- show.php
      -- delete.php
      -- ..etc
首先,让我们在.htaccess中添加规则,这些规则将处理请求并执行.php重定向:

.htaccess 然后,我们需要处理发送给我们的处理程序的path参数,以便我们可以使用它做一些有用的事情。请注意调试注释,它们下面的调用将创建我稍后将显示的输出

graph/index.php
如果您需要进一步简化以理解此建议性解决方案,请告诉我。

子域是否映射到目录?@BenM yes<代码>实验室映射到
/www/labs
。例如:
labs.helloboy.com/graph/
映射到
/www/labs/graph/
,因此我想您需要做两件事:使用graphs/load下的.php扩展名重定向文件(现有的还是不存在的?),删除扩展名(看起来像文件夹?),并将该URL重写为.php等效文件?好吧,这会导致一个无休止的循环,但如果你只是在做重写,那应该很简单。@kjetilh是的,这就是我想要的。但我不擅长url重写…:(正如我所说,执行这两个操作将创建一个无休止的循环。
show.php
将重定向到
show/
,然后show将重写为
show.php
,这将再次重定向到
show/
,等等。如果您可以将URL更改为go,则可以将其重写为。或者您可以将.php文件重命名为例如内部sho。)w、 php然后,如果用户访问
show.php
,您将重定向到
show/
并重写到内部文件。如果我的解释看起来很复杂,请道歉:)。他需要它用于子域实验室,而目录图无法使其工作。。。我想知道这是否是因为
实验室
/www
目录中?
RewriteEngine on

# Make sure index.php requests are NOT rewritten, otherwise we'll end up in an endless loop.
RewriteCond %{HTTP_HOST} ^labs\.helloboy\.com$
RewriteCond %{REQUEST_URI} ^graph/index\.php$
RewriteRule .* - [L,NC,QSA]

# Redirect all .php files and remove the extension
RewriteCond %{HTTP_HOST} ^labs\.helloboy\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(graph/.+)\.php$ $1 [R,NC,QSA]

# Make sure that we won't match existing files or directories, otherwise the lib files will fail. Get the path after "graph/" and add it as a path argument to "graph/index.php".
RewriteCond %{HTTP_HOST} ^labs\.helloboy\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^graph/(.*) graph/index.php?path=$1 [L,NC,QSA]
<?php

// NOTE: Consider returning a 404 status code with the header and possibly a redirect if you can't process the paths sanely.

//======
// DEBUG
//======

?><pre><?php var_export( $_GET ) ?></pre><?php

$path = isset( $_GET['path'] ) ? $_GET['path'] : '';

if ( $path ) {
    // Split the path into parts. For example load/show/ becomes an array with two elements: ['load', 'show']
    $paths = array_filter( explode( '/', $path ) );

    //======
    // DEBUG
    //======


    ?><pre><?php var_export( $paths ) ?></pre><?php

    $len = count( $paths );

    if ( $paths ) {
            // If we have any path we attempt to process it

        if ( $paths[0] === 'load' ) {

            // Do something if load

            if ( $len > 1 ) {
                $action = $paths[1];

                switch ( $action ) {
                    case 'show':
                        $file = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . "$action.php";

                        //======
                        // DEBUG
                        //======

                        var_dump( $file ) ;

                        if ( file_exists( $file ) ) 
                            require_once $file;
                    break;
                }
            }
        }
    }
}

?>
// This is the contents of the supervariabel $_GET
array (
  'path' => 'load/show/',
)

// This is the path parts after splitting and filtering of the path argument
array (
  0 => 'load',
  1 => 'show',
)

// Here we illustrate that we can include/process any file we wish based on the path contents
string '/your/server/path/graph/lib/show.php' (length=xx)