【问题标题】:301 redirect not working joomla301重定向不起作用joomla
【发布时间】:2013-11-27 02:27:01
【问题描述】:

我正在尝试在 joomla 中重写 .htaccess 中的 URL 这是我的 .htaccess

##
# @package      Joomla
# @copyright    Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved.
# @license      GNU General Public License version 2 or later; see LICENSE.txt
##

##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations.  It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file.  If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's.  If they work,
# it has been set by your server administrator and you do not need it set here.
##

## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks

## Mod_rewrite in use.

RewriteEngine On

## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects

##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##

# RewriteBase /

## Begin - Joomla! core SEF Section.
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
Redirect 301 /properties.html?view=property&id=4:land-for-sale-kotturpuram-chennai /land-for-sale-kotturpuram-chennai.html

所以在底部你会看到我正在使用redirect 301

它不起作用。我最终看到 404 页面。在我的 joomla 管理面板中,所有 SEO 设置

搜索引擎友好的 URL,使用 URL 重写,为 URL 添加后缀,Unicode 别名设置为是。

或者还有其他更好的方法可以从 URL 中删除 properties.html?view=property&amp;id=4:

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect joomla


    【解决方案1】:

    Redirect 不匹配 QUERY_STRING 你只需要使用 mod_rewrite 规则。

    在所有规则之前尝试此规则

    RewriteCond %{QUERY_STRING} ^view=property&id=4:land-for-sale-kotturpuram-chennai$ [NC]
    RewriteRule ^properties\.html$ /land-for-sale-kotturpuram-chennai.html? [R=301,L,NE]
    

    【讨论】:

    • 我有 40 多个这样的链接(并且还在增加)。我不能为每个 URL 写 2 行。 properties.html?view=property&amp;id=5:abc-acb-acb-acv 和许多。我想将每个 URL 更改为 SEO 友好 URL。
    • 我为这个特定的 URL 尝试了你的两行代码。它没有用。
    • 事实上,您不能使用 Redirect 指令匹配查询字符串,任何风格的 mod_rewrite 规则都需要 2 行。
    • 好规则肯定有效(我已经测试过了),您只需要确保这是您在.htaccess 中的第一条规则并且您的输入网址是:/properties.html/?view=roperty&amp;id=4:land-for-sale-kotturpuram-chennai
    • 我试过你的概念。没有运气。我提醒您,我只是想重写 URL,实际上不存在这样的 /land-for-sale-kotturpuram-chennai.html 页面。
    猜你喜欢
    • 2023-03-27
    • 2018-02-24
    • 1970-01-01
    • 1970-01-01
    • 2013-06-05
    • 2014-04-30
    • 2011-09-16
    相关资源
    最近更新 更多