【问题标题】:Change displayed URL to show index.php in place of two other file names更改显示的 URL 以显示 index.php 代替其他两个文件名
【发布时间】:2014-11-02 15:29:16
【问题描述】:

我真的不喜欢正则表达式,我很难为我的网站设置规则。

我有两个索引文件,名为index-pc.php 和第二个名为index-mob.php,我希望能够隐藏文件名的-pc/-mob 部分。我应该使用哪种语法?

我目前的规则是:

RewriteEngine On    
RewriteRule ^index-(pc|mob)\.php$ index.php [L]    

但这条规则不起作用。我错过了什么?

谢谢。

【问题讨论】:

    标签: regex url mod-rewrite url-rewriting rewrite


    【解决方案1】:

    正则表达式似乎是正确的。您是否已启用 .htaccess?如果没有,请打开您的 httpd.conf 并更改

    <Directory />
      ....
      AllowOverride None
    </Directory>
    

    <Directory />
      ....
      AllowOverride All
    </Directory>
    

    【讨论】:

    • 感谢您的回答。它与此无关,而只是与我的 .htaccess 中的错误顺序有关,但我现在的问题是 mod_rewrite 进行重定向,然后它不起作用。这会导致 404 错误...实际上 no index.php 文件在那里,我只想显示一个替换名称以隐藏地址中的 -pc-mob 部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-23
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多