.htaccess重定向index.php(.htaccess redirection of index.php)

编程入门 行业动态 更新时间:2024-10-21 18:35:01
.htaccess重定向index.php(.htaccess redirection of index.php)

下面说明了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]

The below illustrates the .htaccess code for a generating SEF url when joomla SEF is on in the backend.

## 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]

I have a simple problem which I'm not able to get my head around into. I put this condition so that if the url is domain.com/index.php then 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.

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

最满意答案

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]

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.

It is due to the wrong regex you're using. Use this rule to remove index.php from URIs:

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

更多推荐

本文发布于:2023-08-02 18:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1379577.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   htaccess   index   redirection   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!