htaccess的谜题,帮助需要 [英] .htaccess puzzle, help needed

查看:202
本文介绍了htaccess的谜题,帮助需要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的链接: 的index.php /论坛/ viewforum / 5 /

现在,我想要那个论坛这个词在URL成为动态的,使得它不断的话,我替换它,它仍然重定向到相同的URL。

例如,如果我有: 产品A / viewforum / 5 / 它重定向到: 论坛/ viewforum / 5 /

例如,如果我有: 产品B / viewforum / 13 / 它重定向到: 论坛/ viewforum / 13 /

在换句话说,如果有一个查看论坛字样的URL,它应该引发这种重写。

我已经有一个的.htaccess,消除在index.php从URL,这样的重写规则应该考虑这一点。

这可能吗?

.htaccess的:

 < IfModule mod_rewrite.c>
RewriteEngine叙述上


重写规则成员的http://%{HTTP_HOST} / 404 [R = 301,L]

的RewriteCond%{ENV:REDIRECT_STATUS} ^ $
重写规则^ [^ /] + /(viewforum / [0-9] + /?)$ /论坛/ $ 1 [L,NC]
的RewriteCond%{} REQUEST_FILENAME!-f

的RewriteCond $ l ^(图片|图标\ .ICO |机器人\ .TXT |的index.php)![NC]
重写规则^(。+)$ /index.php/$1? [L]
< / IfModule>
 

解决方案

您第2和第3的规则看起来嫌疑人。

让您充分code是这样的:

  RewriteEngine叙述上

重写规则成员的http://%{HTTP_HOST} / 404 [R = 301,L]

的RewriteCond%{REQUEST_URI}!^ /论坛/ [NC]
重写规则^ [^ /] + /(viewforum / [0-9] + /?)$ /论坛/ $ 1 [L,NC,R]

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond $ l ^(图片|图标\ .ICO |机器人\ .TXT |的index.php)![NC]
重写规则^(。+)$ /index.php/$1 [L]
 

I have this link: index.php/forums/viewforum/5/

Now, I want that "forums" word in URL to become dynamic such that which ever word I replace it with, it still redirects to the same URL.

For example, if I have: ProductA/viewforum/5/ it redirects to: forums/viewforum/5/

For example, if I have: ProductB/viewforum/13/ it redirects to: forums/viewforum/13/

In other words, if there's a "view forum" word in the URL, it should trigger this rewrite.

I already have a .htaccess that removes the index.php from the URL so the rewrite rule should consider that too.

Is it possible?

HTACCESS:

<IfModule mod_rewrite.c>
RewriteEngine on


RewriteRule member http://%{HTTP_HOST}/404 [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^[^/]+/(viewforum/[0-9]+/?)$ /forums/$1 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond $1 !^(images|favicon\.ico|robots\.txt|index.php) [NC]
RewriteRule ^(.+)$ /index.php/$1? [L]
</IfModule>

解决方案

Your 2nd and 3rd rules look suspect.

Have your full code like this:

RewriteEngine on

RewriteRule member http://%{HTTP_HOST}/404 [R=301,L]

RewriteCond %{REQUEST_URI} !^/forums/ [NC]
RewriteRule ^[^/]+/(viewforum/[0-9]+/?)$ /forums/$1 [L,NC,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(images|favicon\.ico|robots\.txt|index.php) [NC]
RewriteRule ^(.+)$ /index.php/$1 [L]

这篇关于htaccess的谜题,帮助需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆