htaccess重定向不存在文件并显示类似存在的链接

时间:2018-12-12 20:00:10

标签: php .htaccess

这是我的htaccess

_page = await _browser.NewPageAsync();

await _page.SetRequestInterceptionAsync(true);

// disable images to download
_page.Request += (sender, e) =>
{
    if (e.Request.ResourceType == ResourceType.Image)
        e.Request.AbortAsync();
    else
        e.Request.ContinueAsync();
};

通过此htaccess,我可以删除.php,并将“ example.com/member.php?id=1”页面显示为“ example.com/3”。

现在,我想将“ example.com/product.php?id=1”显示为“ example.com/product/1”,但有趣的是,不存在“ product”文件。可以显示为“ example.com/product/1”吗?

谢谢

1 个答案:

答案 0 :(得分:1)

像这样:

RewriteEngine On

RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://example.com%{REQUEST_URI} [NE,R=301,L]

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# product rewrite
RewriteRule ^product/([^/]+)/?$ product.php?id=$1 [L,QSA,NC]

# member rewrite
RewriteRule ^([^/]+)/?$ member.php?id=$1 [L,QSA]