Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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 HT访问重定向到单个文件_Php_.htaccess_Redirect - Fatal编程技术网

Php HT访问重定向到单个文件

Php HT访问重定向到单个文件,php,.htaccess,redirect,Php,.htaccess,Redirect,我想重定向: 到 不更改地址栏中的请求 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?url=$1 如果我使用它,它适用于URL,但不适用于(所有相对URL,如content/styles.css,现在都是foo/content/styles.css,这会导致404错误) 当我加上 [R=301] 重定向是正确的,但它显示了一个“丑陋

我想重定向: 到

不更改地址栏中的请求

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?url=$1
如果我使用它,它适用于URL,但不适用于(所有相对URL,如content/styles.css,现在都是foo/content/styles.css,这会导致404错误)

当我加上

[R=301]
重定向是正确的,但它显示了一个“丑陋”的URL。
有没有办法同时使用这两种方法?

使用以下.htaccess代码:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule . index.php [L]
它所做的是将所有路径和参数重定向到index.php

i、 e 如果域是example.com

因此->请求将被带到index.php文件,即使路径

请求仍将被带到index.php文件

这与laravel等框架使用的代码完全相同

在index.php文件中,您可以使用:

$request_uri=parse_url($_SERVER['REQUEST_URI']);
$path = $request_uri['path'];

$path
变量将为您提供用户输入的路径。

很抱歉浪费了您的时间。我想我会用这种方法