Apache .htaccess中的条件重定向规则

Apache .htaccess中的条件重定向规则,apache,.htaccess,Apache,.htaccess,我需要在.htaccess文件中应用以下规则- 如果url是mysite.com 如果url是mysite.com/index.php或mysite.com/anypage.anyextension 如果url在域后有单词admin作为mysite.com/admin/… 如果url的模式为mysite.com/anyword/或mysite.com/anyword则重定向到mysite.com/somewhere/somepage.php?slug=anyword .htaccess对我来

我需要在.htaccess文件中应用以下规则-

  • 如果url是
    mysite.com
  • 如果url是
    mysite.com/index.php
    mysite.com/anypage.anyextension
  • 如果url在域后有单词admin作为
    mysite.com/admin/…
  • 如果url的模式为
    mysite.com/anyword/
    mysite.com/anyword
    则重定向到
    mysite.com/somewhere/somepage.php?slug=anyword
.htaccess对我来说是一个全新的世界。
有人能帮你吗?

如果你想让一个特定的文件夹执行重定向,例如,模板将是一个新闻文件夹

RewriteEngine On
RewriteRule    ^news/([A-Za-z0-9-]+)/?$    /news/index.php?slug=$1    [NC,L,QSA]    # Process posted item
这会将
yousite.com/news/my first article
重定向到
yoursite.com/news/index.php?slug=my first article

只需确保用实际处理命令的页面替换news和index.php