Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.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
如何使用.htaccess将index.php以外的所有内容转换为参数_.htaccess - Fatal编程技术网

如何使用.htaccess将index.php以外的所有内容转换为参数

如何使用.htaccess将index.php以外的所有内容转换为参数,.htaccess,.htaccess,是否有如下方法使用.htaccess mydomain.com 重定向到 mydomain.com/index.php 及 mydomain.com/index.php之外的所有内容 重定向到 mydomain.com/index.php?u=除index.php之外的所有内容 换句话说,将所有内容(目录、子目录、页面等)转换为一个简单的字符串参数,以通过变量u传递到index.php 任何帮助都将不胜感激。要将所有内容发送到index.php: RewriteEngine On Rewrite

是否有如下方法使用.htaccess

mydomain.com 重定向到 mydomain.com/index.php

mydomain.com/index.php之外的所有内容 重定向到 mydomain.com/index.php?u=除index.php之外的所有内容

换句话说,将所有内容(目录、子目录、页面等)转换为一个简单的字符串参数,以通过变量u传递到index.php


任何帮助都将不胜感激。

要将所有内容发送到index.php:

RewriteEngine On
RewriteCond %{REQUEST_URI} !index.php
RewriteRule (.*) index.php?u=$1 [QSA,L]
请注意,这还将向index.php发送对图像、css、javascript等的请求。因为这可能不是您想要的,所以这个可能更合适:

RewriteEngine On
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?u=$1 [QSA,L]
这将把所有不存在的文件和目录请求发送到index.php。注意,这意味着htdocs文件夹中的任何内容都可以通过其url访问。所以这取决于你的htdocs文件夹大部分是空的