2015-05-24 100 views
0

我的.htaccess文件有问题。 我最近搬到那是在一个子目录中的根路径论坛(IPB),所以我写了这个.htaccess文件.htaccess移动论坛和SEO网址

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文件,这将是新的网站,我想搜索引擎友好的URL,所以我写了这条线

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

但这种规则不起作用。 像

www.domain.com/view/welcome/ 

每个请求重定向到一个404页的IPB论坛。

我也试过放一些RewriteCond,但结果是一样的, 每个涉及根路径中新index.php的url都会变成一个404页面。

编辑: 在/论坛/ 有此.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> 

回答

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 
+0

还没干活G。我相信问题是我用来将请求重定向到/ forum /的规则,但我现在不能找到解决方案 – divby0

+0

。我已经扩展了答案 – splash58

+0

不,这不起作用。 – divby0

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并非由自身的URL处理你将映射(我认为这允许外部访问)

所以我结束了与.htaccess从@ splash58(谢谢!)