0

这让我难过了几天。任何帮助将不胜感激。

我认为 htaccess 可能是做我需要的最好的方法,但如果你有不同的 sdolution,我很高兴听到它。

我正在使用 joomla 作为我的 CMS,现在我有一个 .htacces 文件,它将获取所有 url 并将它们发送到我网站的社区组件。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?option=com_comprofiler&task=userProfile&user='$1' [L]


# RewriteRule ^(.*) index.php?cb_username=$1
RewriteCond %{REQUEST_FILENAME} !.(jpg|jpeg|gif|png|css|js|pl|txt)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php

但是,这将重定向没有与之关联的目录或文件的每个页面 Url。

我需要的是 htaccess 文件仅在 URL 包含字符串“community/profile/user”时才重定向它们

我仍然认为自己是个菜鸟,而且我已经花了很多天试图解决这个问题。

希望其他人可以在这里阐明这个问题。下面是我的 .htaccess 文件的完整代码

 ##
# @version $Id: htaccess.txt 1005 2006-10-05 18:00:00Z stingrey $
# @package Joomla
# @copyright Copyright (C) 2006 Open Source Matters. All rights reserved.
# @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##
Options +FollowSymLinks
#
# mod_rewrite in use
#
RewriteEngine On
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update YourJoomlaDirectory (just / for root)

RewriteBase /

#
# Rules
#
#
# ProfileRedirector V 1.3
#
# Make sure your host allows option override
# and has ModRewrite installed

# activate Rewrite enginge

RewriteEngine On


RewriteBase /

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?option=com_comprofiler&task=userProfile&user='$1' [L]


# RewriteRule ^(.*) index.php?cb_username=$1
RewriteCond %{REQUEST_FILENAME} !.(jpg|jpeg|gif|png|css|js|pl|txt)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
4

1 回答 1

0

首先你应该删除双RewriteBaseRewriteEngine

现在,你的意思是这样的:

Options +FollowSymLinks
RewriteBase /

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} \.(jpg|jpeg|gif|png|css|js|pl|txt)$
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1 [L]

RewriteRule ^(.*)community/profile/user/(.*)$ index.php?option=com_comprofiler&task=userProfile&user=$2 [L]

第一次重写不应该改变所有图像文件的路径。如果 URL 包含community/profile/user/,则将 url 重写为index.php?option=com_comprofiler&task=userProfile&user={what-comes-after-user/}

您应该非常小心使用 .htaccess 编写的内容,因为简单的空格或缺少大写字母可能会导致无法加载任何页面的致命错误。

我希望这可以帮助你。

于 2012-03-04T19:59:16.983 回答