我一直在努力让我的重写规则以我想要的方式工作

时间:2015-11-23 02:08:29

标签: php wordpress .htaccess mod-rewrite mybb

这将是一个冗长的帖子。请耐心等待。

  

我的目录结构

public_html
    agentc0re
       blog
       forum
       etc..
    other doamins
  

我的.htaccess文件

的public_html

Options +FollowSymlinks +Includes +SymLinksIfOwnerMatch +ExecCGI -MultiViews -Indexes
<files .htaccess>
   Order allow,deny
   Deny from all
</files>

ErrorDocument 404 /agentc0re/404/index.html

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.agentc0re.com$ [NC]
RewriteRule ^(.*)$ http://agentc0re.com/$1 [R=301,L,NC]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.agentc0re.com$ [NC]
RewriteRule ^(.*)$ https://agentc0re.com/$1 [R=301,L,NC]

RewriteCond %{HTTP_HOST} ^(www.)?agentc0re.com$ [NC]
RewriteCond %{REQUEST_URI} !^/agentc0re/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /agentc0re/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?agentc0re.com$ [NC]
RewriteRule ^(/)?$ agentc0re/index.php [L]
</IfModule>

agentc0re

Options +FollowSymlinks +Includes +SymLinksIfOwnerMatch +ExecCGI -MultiViews -Indexes
<files .htaccess>
   Order allow,deny
   Deny from all
</files>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /agentc0re

RewriteRule ^Home/?$ /index.php?page= [L]
RewriteRule ^Blog/?$ /index.php?page=blog [L]
RewriteRule ^Forum/?$ /index.php?page=forum/index [L]
RewriteRule ^Sub_Counter/?$ /index.php?page=SubCounter/subCounter [L]
RewriteRule ^AboutMe/?$ /index.php?page=aboutme [L]
RewriteRule ^Contact/?$ /index.php?page=contact [L]

RewriteBase /agentc0re/forum

RewriteRule ^forum-([0-9]+)\.html$ forumdisplay.php?fid=$1 [L,QSA]
RewriteRule ^forum-([0-9]+)-page-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2 [L,QSA]

RewriteRule ^thread-([0-9]+)\.html$ showthread.php?tid=$1 [L,QSA]
RewriteRule ^thread-([0-9]+)-page-([0-9]+)\.html$ showthread.php?tid=$1&page=$2 [L,QSA]
RewriteRule ^thread-([0-9]+)-lastpost\.html$ showthread.php?tid=$1&action=lastpost [L,QSA]
RewriteRule ^thread-([0-9]+)-nextnewest\.html$ showthread.php?tid=$1&action=nextnewest [L,QSA]
RewriteRule ^thread-([0-9]+)-nextoldest\.html$ showthread.php?tid=$1&action=nextoldest [L,QSA]
RewriteRule ^thread-([0-9]+)-newpost\.html$ showthread.php?tid=$1&action=newpost [L,QSA]
RewriteRule ^thread-([0-9]+)-post-([0-9]+)\.html$ showthread.php?tid=$1&pid=$2 [L,QSA]

RewriteRule ^post-([0-9]+)\.html$ showthread.php?pid=$1 [L,QSA]

RewriteRule ^announcement-([0-9]+)\.html$ announcements.php?aid=$1 [L,QSA]

RewriteRule ^user-([0-9]+)\.html$ member.php?action=profile&uid=$1 [L,QSA]

RewriteRule ^calendar-([0-9]+)\.html$ calendar.php?calendar=$1 [L,QSA]
RewriteRule ^calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)\.html$ calendar.php?calendar=$1&year=$2&month=$3 [L,QSA]
RewriteRule ^calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)-day-([0-9]+)\.html$ calendar.php?action=dayview&calendar=$1&year=$2&month=$3&day=$4 [L,QSA]
RewriteRule ^calendar-([0-9]+)-week-(n?[0-9]+)\.html$ calendar.php?action=weekview&calendar=$1&week=$2 [L,QSA]

RewriteRule ^event-([0-9]+)\.html$ calendar.php?action=event&eid=$1 [L,QSA]

博客

Options +FollowSymlinks +Includes +SymLinksIfOwnerMatch +ExecCGI -MultiViews -Indexes
<files .htaccess>
   Order allow,deny
   Deny from all
</files>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ../index.php?page=blog [L,NC]
</IfModule>

论坛

Options +FollowSymlinks +Includes +SymLinksIfOwnerMatch +ExecCGI -MultiViews -Indexes
<files .htaccess>
   Order allow,deny
   Deny from all
</files>
#
# If mod_security is enabled, attempt to disable it.
# - Note, this will work on the majority of hosts but on
#   MediaTemple, it is known to cause random Internal Server
#   errors. For MediaTemple, please remove the block below
#
<IfModule mod_security.c>
    # Turn off mod_security filtering.
    SecFilterEngine Off

    # The below probably isn't needed, but better safe than sorry.
    SecFilterScanPOST Off
</IfModule>

#
# MyBB "search engine friendly" URL rewrites
# - Note, for these to work with MyBB please make sure you have
#   the setting enabled in the Admin CP and you have this file
#   named .htaccess
#
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /agentc0re/forum

    RewriteRule ^forum-([0-9]+)\.html$ forumdisplay.php?fid=$1 [L,QSA]
    RewriteRule ^forum-([0-9]+)-page-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2 [L,QSA]

    RewriteRule ^thread-([0-9]+)\.html$ showthread.php?tid=$1 [L,QSA]
    RewriteRule ^thread-([0-9]+)-page-([0-9]+)\.html$ showthread.php?tid=$1&page=$2 [L,QSA]
    RewriteRule ^thread-([0-9]+)-lastpost\.html$ showthread.php?tid=$1&action=lastpost [L,QSA]
    RewriteRule ^thread-([0-9]+)-nextnewest\.html$ showthread.php?tid=$1&action=nextnewest [L,QSA]
    RewriteRule ^thread-([0-9]+)-nextoldest\.html$ showthread.php?tid=$1&action=nextoldest [L,QSA]
    RewriteRule ^thread-([0-9]+)-newpost\.html$ showthread.php?tid=$1&action=newpost [L,QSA]
    RewriteRule ^thread-([0-9]+)-post-([0-9]+)\.html$ showthread.php?tid=$1&pid=$2 [L,QSA]

    RewriteRule ^post-([0-9]+)\.html$ showthread.php?pid=$1 [L,QSA]

    RewriteRule ^announcement-([0-9]+)\.html$ announcements.php?aid=$1 [L,QSA]

    RewriteRule ^user-([0-9]+)\.html$ member.php?action=profile&uid=$1 [L,QSA]

    RewriteRule ^calendar-([0-9]+)\.html$ calendar.php?calendar=$1 [L,QSA]
    RewriteRule ^calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)\.html$ calendar.php?calendar=$1&year=$2&month=$3 [L,QSA]
    RewriteRule ^calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)-day-([0-9]+)\.html$ calendar.php?action=dayview&calendar=$1&year=$2&month=$3&day=$4 [L,QSA]
    RewriteRule ^calendar-([0-9]+)-week-(n?[0-9]+)\.html$ calendar.php?action=weekview&calendar=$1&week=$2 [L,QSA]

    RewriteRule ^event-([0-9]+)\.html$ calendar.php?action=event&eid=$1 [L,QSA]

    <IfModule mod_env.c>
            SetEnv SEO_SUPPORT 1
    </IfModule>
</IfModule>

#
# If Apache is compiled with built in mod_deflade/GZIP support
# then GZIP Javascript, CSS, HTML and XML so they're sent to
# the client faster.
#
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE application/javascript text/css text/html text/xml
</IfModule>

# Note: You are able to choose a different name in the Admin CP. If you've done that you need to change it here too
<Files "error.log">
    Order Deny,Allow
    Deny from all
</Files>
  

这是做什么的

的public_html

将www版本重定向到我网站的非www版本。然后它从URL中删除agentc0re。

agentc0re

我为我的网站使用动态PHP包含。也加载我的标题,内容,页脚所有通过PHP包括。这是第一套重写规则的作用。他们使我的网站上的菜单栏工作...有点(更多信息)。下一组具有重写基础&#34; / agentc0re / forum&#34;是因为如果您要从http://example.com/Forum(重写规则到我的index.php包含文件)查看我的网站,那么论坛链接无法正常工作。

博客

这有效地将博客与我的标题+菜单一起加载,就像主页一样。没有这个,wordpress就会自行加载。

论坛

myBB的默认重写规则

  

需要修复的内容

博客问题

如果你现在还没有弄清楚my webiste is this。如果你看菜单链接,他们看起来用户友好/好。他们也都去了应有的地方。您可以通过将鼠标悬停在浏览器上并查看浏览器底部来查看它们。

现在点击博客。那么这就是狗屎变得怪异的地方。现在所有菜单链接都已更改。他们是博客/主页,博客/博客等。 这是我需要修复的一项

其次,点击我博客中的链接。现在该死的菜单链接变化更多。我认为这与上述问题有关。我不知道为什么,但我知道它不是与wordpress相关的,因为它也发生在我的论坛链接上。除非他们都做了导致这种情况的怪异事。

论坛问题

与博客类似,当您点击论坛中的链接时,菜单的链接会发生变化。但最初点击论坛并没有像点击博客时那样产生类似的结果。

  

我希望看到发生的事情

适用于博客

当有人点击菜单中的博客并在博客中导航时,链接显示为

 http://example.com/Blog/*

论坛

与博客一样,我也希望论坛能够发生同样的事情。

1 个答案:

答案 0 :(得分:1)

在PHP文件中,部分:

<div id='cssmenu' class='align-center'>
  <ul>
    <li><a href='Home'>Home</a>
    </li>
    <li><a href='Blog'>Blog</a>
    </li>
    <li><a href='Forum'>Forum</a>
    </li>
    <li><a href='#'>Youtube Resources</a>
      <ul>
        <!--<li><a href='index.php?page=/SubCounter/subCounter' target="_top">YTG Sub Counter</a></li>-->
        <li><a href='Sub_Counter' target="_top">YTG Sub Counter</a>
        </li>
      </ul>
    </li>
    <li><a href='#'>Other Sites</a>
      <ul>
        <li><a href='http://extralifealerts.com' target='_blank'>Extra-Life Alerts</a>
        </li>
        <li><a href='http://learnix.net' target='_blank'>Learnix.net</a>
        </li>
      </ul>
    </li>
    <!--<li><a href='index.php?page=aboutme'>About Me</a></li>
        <li><a href='index.php?page=contact'>Contact</a></li>-->
    <li><a href='AboutMe'>About Me</a>
    </li>
    <li><a href='Contact'>Contact</a>
    </li>
  </ul>
</div>

需要有绝对的链接,而不是相对的链接。所以,对于例如。将a[href]更改为:

    <li><a href='/Home'>Home</a>
    </li>
    <li><a href='/Blog'>Blog</a>
    </li>

那就是全部。