简体   繁体   中英

How to make http://example.com/test.php to http://example.com/index.php?do=test using .htaccess?

I have a default url http://example.com/test.php
I want to make this url to http://example.com/index.php?do=test


http://example.com/test.php to http://example.com/index.php?do=test

I am using below code, but not working...

RewriteEngine On
RewriteCond %{REQUEST_URI} !^index\.php$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(\w+)\.php$ index.php?do=$1 [L]

Thanks in advance.

This will do the trick:

RewriteEngine On
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^(\w+)\.php$ index.php?do=$1 [L]
RewriteCond %{REQUEST_FILENAME} -f

Use following

.htaccess file

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>

URL : http://localhost/index.php?do=test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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