如何重写 URL 以删除 index.php 并使用 codeigniter 强制小写?
我在使用 .htaccess 同时执行这两项操作时遇到困难。
删除index.php 可以正常工作,但尝试添加强制小写字母会引发 500 错误。我正在使用代码点火器。任何帮助表示赞赏!
这是我的 .htaccess 代码:
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]
I’m having trouble doing both of these at once with .htaccess.
Removing index.php is working, but trying to add the force lowercase keeps throwing a 500 error. I am using codeigniter. Any help is appreciated!
here’s my .htaccess code:
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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那是因为这是不可能的,让我解释一下。
但除此之外,此 RewriteMap 只能在您的 Httpd.conf 文件中声明,您可以在那里声明它with:
然后在你的 .htaccess 文件中使用你的变量 lc ,但同样只有两者之一会获胜,你不能同时拥有两者。
您要么获得小写的 URL,要么让网站在不使用 index.php 的情况下正常工作,因为由于每个人所做的事情的性质,它们总是会发生冲突。
实际上,我能看到它发生的唯一方法是在 php 中,如下所示:
我会将其放入类的主要构造中,我希望这对您有所帮助。
That is because it is impossible, let me explain.
BUT beyond all this RewriteMap can only be declared in your Httpd.conf file, you would declare it there with:
Then in your .htaccess file use your variable lc, but then again only one of the two will win you can't have both.
You will either get the URL lowercase or have the site working without using the index.php because they are always going to conflict because of the nature of what each one does.
Really the only way I can see it happening is in php, like so:
This I would put into the main construct of your classes, I hope this helps you.
如果您只是想强制使用小写,则建议的 php 代码不起作用。下面是正确的 php 代码。
此处找到讨论 强制小写 .htaccess
The php code suggested does not work if you are just trying to force to lowercase. Below is the correct php code.
Discussion Found Here Force lowercase .htaccess