dtfbj24048 2016-01-25 21:41
浏览 260
已采纳

301使用通配符和.htaccess重定向

I'm new to using 301 redirects so I don't know if this is possible, but I want to take part of the old url and use it in the new url using wildcards.

example.com/folder/file.php to

example.com/newfolder/newfolder/file-keyword/

Where the file name is a wildcard and the name of the file (without the .php) is inserted into the new url example.com/newfolder/newfolder/{insert the file name here}-keyword/

  • 写回答

1条回答 默认 最新

  • dongnvwang8591 2016-01-25 23:13
    关注

    You can use a RewriteRule to accomplish this. For example:

    # if its going in your [docRoot]/folder/.htaccess:
    RewriteRule ^(.+)\.php http://example.com/newfolder/newfolder/$1-keyword/

    # if its going in your [docRoot]/.htaccess:
    RewriteRule ^folder/(.+)\.php http://example.com/newfolder/newfolder/$1-keyword/

    # if its going in your main config:
    RewriteRule ^/folder/(.+)\.php http://example.com/newfolder/newfolder/$1-keyword/

    This assumes that your rewrite module is loaded in the main config:
    LoadModule rewrite_module modules/mod_rewrite.so

    And enabled in the same scope you declare your RewriteRule:
    RewriteEngine On

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line