.htaccess 基于URL选择,使用.html扩展名进行动态URL重写的htaccess

.htaccess 基于URL选择,使用.html扩展名进行动态URL重写的htaccess,.htaccess,mod-rewrite,url-rewriting,dynamic-url,htmlextensions,.htaccess,Mod Rewrite,Url Rewriting,Dynamic Url,Htmlextensions,我正试图重写一些动态页面url,其中数据是用slug从数据库中获取的,就像这样 Options +FollowSymlinks RewriteEngine On RewriteBase /testweb/ RewriteCond %{REQUEST_FILENAME} !-d [NC] RewriteCond %{REQUEST_FILENAME} !-f [NC] RewriteRule ^(.

我正试图重写一些动态页面url,其中数据是用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]
它可以很好地与

但是我需要根据下面单击的任何链接更改重写规则

        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/news/这是另一个链接','/testweb/commissionals/testlink'

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

也请告诉我如何更正下面的代码

        Options +FollowSymlinks
        RewriteEngine on
        RewriteRule ^(.*)\.html$ faq_pages.php?page=$1
我需要在地址栏中显示html URL,如“/testweb/this-is-a-link.html”或“/testweb/faq/this-is-a-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/other-faq-test.html, /testweb/faq/other-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]

嗨,谢谢你的回答。我使用RewriteRule^faq/*/$faq\u pages.php?id=$1[QSA]和RewriteRule^faq/*$faq\u pages.php?id=$1[QSA]重写testweb/faq/other-faq-test.html/和testweb/faq/other-faq-test.html。请告诉我这样做是否正确。另外,请帮助我忽略/重写“faq”文件夹,因为当前没有加载css或图像,因为url中有“faq/”。谢谢lot@user2669827不要使用两条规则,只需添加一条?在/之后。如果您在/faq/中请求静态文件,则2个重写条件会阻止规则的应用。再次感谢。重写规则^faq/*/?$faq_pages.php?id=$1[QSA]不适用于/testweb/faq/other-faq-test.html/。我使用“faq/”和“news/”只是为了检查url并重写到不同的页面。我没有这些名字的文件夹。如何忽略它或指定它们不是目录。。现在,url将查找文件夹“faq”@user2669827使用正则表达式:^faq/*?/?$。在你的问题或其他东西中设置代码的格式,在评论中阅读是不可能的。。现在html/url也在工作。我将编辑这个问题。非常感谢。