【问题标题】:.htaccess redirection of index.phpindex.php 的.htaccess 重定向
【发布时间】:2013-11-28 11:36:01
【问题描述】:

下面说明了当 joomla SEF 在后端打开时生成 SEF url 的 .htaccess 代码。

## Begin - Joomla! core SEF Section.
#
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]

我有一个简单的问题,我无法解决。 我设置了这个条件,以便如果 url 是 domain.com/index.php 那么它应该转到 domain.com 并且只有当模式与 index.php 完全匹配时才会发生这种情况。 但是,所有网址都会发生这种情况。

RewriteCond %{THE_REQUEST} [^.]*|/(index.php)$
RewriteRule ^index.php$ / [R=301,L]

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite joomla


    【解决方案1】:

    it should go to domain.com and this should happen only if the pattern matches exactly as index.php. However this happens for all urls.

    这是由于您使用了错误的正则表达式。使用此规则从 URI 中删除 index.php

    RewriteCond %{REQUEST_URI} !/administrator [NC]
    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
    

    【讨论】:

    • 你能告诉我为什么你没有在 RewriteCond 的末尾使用 $,因为 $ 意味着行尾不是吗?
    • 谢谢。它主要做我想做的事。但是它也会影响 joomla 的管理员文件夹,并且不允许我登录。不断重定向到登录屏幕。我能以某种方式阻止这种情况吗?
    • 谢谢anubhava ..我几分钟前才这样做..正要更新我的评论..
    • 我想再问你一个问题,为什么我们在 ReWriteCond 和 RewriteRule 中使用 index.php 我不明白。我尝试检查文档,但我仍然感到困惑。 !!
    • 实际上也有办法从RewriteCond %{THE_REQUEST} 捕获它,但这主要是因为我使用RewriteRule 容易捕获。
    猜你喜欢
    • 1970-01-01
    • 2013-01-21
    • 2014-08-31
    • 2023-04-10
    • 1970-01-01
    • 2018-05-27
    • 2012-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多