移动论坛和搜索引擎优化的.htaccess

时间:2015-05-24 13:47:37

标签: php apache .htaccess mod-rewrite redirect

我的.htaccess文件存在问题。 我最近移动了一个子目录中根路径中的论坛(IPB),所以我写了这个.htaccess文件

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

RewriteRule ^view/([0-9]+)/?$ index.php?view=$1 [NC,L]

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/forum/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /forum/$1

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ forum/index.php 

这非常有效。 基本上,我希望那些指向论坛的旧网址被重定向到论坛子目录。

但这是问题所在。 在根路径中,有一个index.php将成为新网站,我想要SEO友好的网址,所以我写了这一行

RewriteRule ^view/([0-9]+)/?$ index.php?view=$1 [NC,L]

但这条规则不起作用。 每个请求都像

www.domain.com/view/welcome/

重定向到IPB论坛的404页。

我还尝试了一些RewriteCond但结果是一样的, 涉及根路径中的新index.php的每个url都会转到404 Page。

编辑: 在/论坛/ 这是.htaccess

ErrorDocument 401 /401.shtml
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /forum

RewriteCond %{REQUEST_FILENAME} .*\.(jpeg|jpg|gif|png)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /public/404.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,QSA]

</IfModule>

2 个答案:

答案 0 :(得分:0)

在下面的规则中,您只匹配查看后的数字,但想要welcome

RewriteRule ^view/([0-9]+)/?$ index.php?view=$1 [NC,L]

更改为

RewriteRule ^view/(.+)/?$ index.php?view=$1 [NC,L]

并添加一些行来排除不必要的重定向

RewriteRule ^view/(.+)/?$ index.php?view=$1 [NC,L]

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/forum/
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /forum/$1

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(/)?$ forum/index.php

答案 1 :(得分:0)

我发现了问题! 我正在使用它:

/* Configuration: Path to IP.Board */
define( 'IPB_LOC', 'forum/' );
define( 'IPS_ENFORCE_ACCESS', TRUE );//DAMN COSTANT

/* Load IP.Board files */
require_once( IPB_LOC . 'conf_global.php' );
require_once( IPB_LOC . 'initdata.php' );
require_once( IPB_LOC . CP_DIRECTORY. '/sources/base/ipsRegistry.php' );

/* Init Registry */
ipsRegistry::init();

/* Fetch Member */
$member = ipsRegistry::member()->fetchMemberData(); 
$loggedIn = (bool) $member['member_id'];

检查用户是否已登录论坛,但我没有写过这一行

define( 'IPS_ENFORCE_ACCESS', TRUE );//DAMN COSTANT

告诉IPB不要自己处理你要映射的网址(我认为这允许外部访问)

所以我最终得到了来自@ splash58的.htaccess(谢谢!)

相关问题