dtfbj24048 2016-01-25 13: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 15: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

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部