0

我想我不明白 .htaccess 重写是如何工作的,所以我请求你的帮助。我需要将http://www.mywebsite.com/index.php?name=first更改为http://www.mywebsite.com/first。这可能吗?我当前的 .htaccess 文件的内容是:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^/(.*)$ /index.php?menu=$1 [L]

显然它不起作用。.htaccess 文件的内容是什么?

4

3 回答 3

1

为什么不在 .htaccess 中使用它

<IfModule mod_rewrite.c>

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule 
^(.*)/?$ index.php?page=$1 [L]

</IfModule>

然后在您的 index.php 中返回相应的页面:

# SELECT WHICH PAGE TO DISPLAY
function getPage($showPage) {
    $modules = array(#never name the slugs as same as the php pages
    '/sign-in/i' => 'register.php',
    '/signout/i' => 'logout.php',
    '/staff/i' => 'admin.php',
    '/products/i' => 'blank.php',
    );
    foreach ($modules as $slug=>$phpmodule) {
        if(preg_match($slug, $showPage)) { 
            return $phpmodule;
        }
    } 
    return 'blank.php';#in case module not found display 404 page
}

if (isset($_GET['page'])) {
require_once (getPage($_GET['page'])); #include the appropriate module file
}

有很多方法可以做到。我希望这能让您知道从哪里开始,如果我的回答对您有用,请投票或接受答案。

于 2014-10-22T12:58:12.087 回答
1

尝试这个:

Options All -Indexes

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php?name=$1 [L]
于 2014-10-22T09:57:29.290 回答
0

只需将其放入您的 .htaccess 文件中

<IfModule mod_rewrite.c>

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule 
^(.*)/?$ index.php?name=$1 [L]

</IfModule>
于 2014-10-22T10:21:39.807 回答