繁体   English   中英

使用index.php将网址重定向到非index.php并将字符下划线重定向到破折号(.htaccess)

[英]Redirect url with index.php to non index.php AND character underscore to dashes (.htaccess)

在默认情况下。 Codeigniter网址的每个网址中都有index.php,然后使用下划线。

现在是我的配置。

在Routes.php中,我已将$route['translate_uri_dashes'] = TRUE;设置$route['translate_uri_dashes'] = TRUE; 这意味着当我尝试输入example.some_path时,它将转到example.some-path

在我的congfig.php中。

$config['index_page'] = '';// remove'index.php';

我的.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

# Don't listing directory
Options -Indexes
ErrorDocument 403 http://example/404

# Origin setting
SetEnvIf Origin "http(s)?://(.+\.)?example\.com(:\d{1,5})?$" CORS=$0

Header set Access-Control-Allow-Origin "%{CORS}e" env=CORS
Header merge  Vary "Origin"

现在发行。

1)是,example.com或example.com/somepath(不带index.php)正在运行。 但是example.com/index.php或example.com/index.php/somepath仍然可用,并且也可以正常工作。 访客访问它时,即使我的robots.txt没有索引,也会出现重复的内容错误。 那么如何无法访问index.php呢? 与.htaccess?

2)设置$route['translate_uri_dashes'] = TRUE; ,所有带有下划线的链接会自动转换为破折号(一旦我单击包含下划线的网站中的链接,就会自动插入index.php)。(例如:单击链接<a href="http://example.com/some_path">my link</a> ,它将转换为example.com/index.php/some-path)。 当我尝试直接访问example.com/some-path时,无需单击我网站上的任何链接。 是的,example.com / some-path可以正常工作。

如何确保index.php无法访问并自动重定向到非index.php?

您可以像我一样尝试使用web.config。 我不太喜欢.htaccess,也许是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Imported Rule 1" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll">
              <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
          </rule>
      </rules>
    </rewrite>
        <directoryBrowse enabled="true" />
  </system.webServer>
</configuration>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM