我有一个默认网址http://example.com/test.php
我想将此网址设为http://example.com/index.php?do=test
http://example.com/test.php
至http://example.com/index.php?do=test
我使用下面的代码,但没有工作......
RewriteEngine On
RewriteCond %{REQUEST_URI} !^index\.php$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(\w+)\.php$ index.php?do=$1 [L]
提前致谢。
答案 0 :(得分:1)
这样可以解决问题:
RewriteEngine On
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^(\w+)\.php$ index.php?do=$1 [L]
RewriteCond %{REQUEST_FILENAME} -f
答案 1 :(得分:0)
使用以下
.htaccess文件
RewriteEngine On
RewriteRule ^(.+)$ index.php?do=$1 [QSA,L]
的index.php
<?php
if(isset($_GET['do']) && !empty($_GET['do'])){
include $_GET['do'] . '.php';
} else {
//include 'index.php';
//You can include your default file or Error page here
}
?>
test.php的
<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
Hello You are in Test Page
</body>
</html>