【问题标题】:.htaccess change wordpress hompage but keep the link.htaccess 更改 wordpress 主页但保留链接
【发布时间】:2020-03-31 10:12:38
【问题描述】:

example.com/wp 或者 example.com/wp/

我的静态页面(其中几个 tbh)存储在 root/subf1/

我能够重定向到所需的子文件夹,但路径也显示在 URL 中。 是否可以将 example.com/subf1 更改为 example/wp?

这是我当前的 htaccess。也许我需要在静态页面文件夹中创建另一个?

<IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{HTTP_HOST} ^(www.)?example.com$
      RewriteCond %{REQUEST_URI} !^/subf1/
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ /test/page/$1
      RewriteCond %{HTTP_HOST} ^(www.)?example.com$
      RewriteRule ^(/)?$ /subf1/index.html [L] 
 </IfModule>

RedirectMatch "^/wp$" "https://example.com/subf1/"

非常感谢您的宝贵时间

【问题讨论】:

    标签: regex wordpress apache web server


    【解决方案1】:

    RedirectMatch 仅执行“外部重定向”,因此您可能希望使用 RewriteRule(不带 R 标志)进行内部重定向。

    所以代替 RedirectMatch 试试:

    RewriteRule ^wp$ https://example.com/subf1/ [L]
    

    PS:通常最好使用 redirect/redirectmatch 而不是使用 mod_rewrite,但如果您已经在使用 mod_rewrite 指令,那么坚持使用它而不是混合使用其中一个或另一个指令会更容易混淆。

    【讨论】:

    • 我也认为普通重定向更容易维护,但是......现在不仅来自 /wp/ 的主页,而且所有其他旧页面都被重定向到 /subf1/ 这就是我的代码m 在RewriteRule ^wp/$ /subf1/ 上使用`RewriteEngine` 是否可以只重定向主页(访问/wp/ 时会打开),但不处理wp/?page_id=12 等请求?
    • 您需要在 rewriteconds 中检查 query_string 才能做到这一点
    猜你喜欢
    • 2013-04-24
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多