htaccess用于动态URL重写,扩展名为.html,基于URL选择



我正在尝试重写一些动态页面url,其中数据是用类似"this-is-link"的slug从数据库中获取的。

        Options +FollowSymlinks
        RewriteEngine On
        RewriteBase /testweb/
        RewriteCond %{REQUEST_FILENAME} !-d [NC]
        RewriteCond %{REQUEST_FILENAME} !-f [NC]
        RewriteRule ^(.*)$ faq_pages.php?page=$1 [QSA,L]

它适用于http://www.test.com/testweb/this-is-a-link

但我需要根据点击的任何链接更改重写规则,如下所示。

http://www.test.com/testweb/faq/this-is-a-link,'testweb/news/this is other link','/testweb/contensions/test-link'

上述RewriteRule中的"faq_pages.php"应更改为"news_pages.php"。我如何动态地拥有它,以便可以用于具有相同htaccess的每个页面,或者我如何在htaccess中检查并将值重写到不同的页面。

还请建议我如何更正以下代码。

        Options +FollowSymlinks
        RewriteEngine on
        RewriteRule ^(.*).html$ faq_pages.php?page=$1

我需要在地址栏中显示html URL,如"/testweb/this-is-link.html"或"/testweb/faq/this-is-link.html"

编辑:在Jon Lin的帮助下,我更新了以下代码。

        Options +FollowSymlinks
        RewriteEngine On
        RewriteBase /testweb/
        RewriteCond %{REQUEST_FILENAME} !-d [NC]
        RewriteCond %{REQUEST_FILENAME} !-f [NC]
        RewriteRule ^faq/(.*?)/?$ faq_pages.php?page=$1 [QSA]

现在,以下两个条件都起作用:/testweb/faq/另一个faqtest.html,
/testweb/faq/aother-faq-test.html/

由于我没有任何名为"faq"的子文件夹,根文件夹中的模板文件(images/css/js等)没有加载。我该怎么修?

感谢

你在找这样的东西吗?

    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /testweb/
    RewriteCond %{REQUEST_FILENAME} !-d [NC]
    RewriteCond %{REQUEST_FILENAME} !-f [NC]
    RewriteRule ^faq/(.*)$ faq_pages.php?page=$1 [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-d [NC]
    RewriteCond %{REQUEST_FILENAME} !-f [NC]
    RewriteRule ^news/(.*)$ news_pages.php?page=$1 [QSA,L]

最新更新