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

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/

图片转代码服务由CSDN问答提供 功能建议

我是新手使用301重定向所以我不知道这是否可行,但我想采取 旧网址的一部分,并使用通配符在新网址中使用它。

example.com/folder/file.php到

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

文件名是通配符,文件名(不带.php)插入到新的url example.com/newfolder中 / newfolder / {在此插入文件名} -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

    打赏 评论