.htaccess 如何重写URL以删除index.php并使用codeigniter强制使用小写?
我无法使用.htaccess同时执行这两个操作 删除index.php是可行的,但尝试添加强制小写会引发500错误。我正在使用codeigniter。感谢您的帮助 这是我的.htaccess代码:.htaccess 如何重写URL以删除index.php并使用codeigniter强制使用小写?,.htaccess,codeigniter,mod-rewrite,.htaccess,Codeigniter,Mod Rewrite,我无法使用.htaccess同时执行这两个操作 删除index.php是可行的,但尝试添加强制小写会引发500错误。我正在使用codeigniter。感谢您的帮助 这是我的.htaccess代码: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?$1 RewriteMap lc int:tolower Re
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
那是因为这是不可能的,让我解释一下
RewriteMap lc int:tolower
然后在.htaccess文件中使用变量lc,但同样,这两个变量中只有一个会赢,而不能同时拥有这两个变量
您可以使用小写URL,也可以在不使用index.php的情况下让站点正常工作,因为它们总是会发生冲突,这是因为它们各自的工作性质不同
实际上,我能看到它发生的唯一方式是在php中,如下所示:
$this->load->helper('url');
$your_URL = uri_string();
preg_match_all('/[A-Z]/', $your_URL, $match) ;
$total_count = count($match [0]);
if($total_count > 0){
$new_line = strtolower($your_URL);
redirect($new_line);
}
我会把它放在你的类的主要结构中,我希望这对你有所帮助 如果您只是试图强制使用小写,则建议的php代码不起作用。下面是正确的php代码
$url = $_SERVER['REQUEST_URI'];
$pattern = '/([A-Z]+)/';
if(preg_match($pattern, $url)) {
$new_url = strtolower($url);
Header( 'HTTP/1.1 301 Moved Permanently' );
Header( 'Location: ' . $new_url );
exit;
}
// your code here
这里有讨论