我的page1.php文件位于中
/public_html/mypages/page1.php
如果用户请求www.myurl.com/Mypages/Page1.php
返回file not found
我如何确保每个请求都得到处理而不考虑的情况
我正在使用godaddy linux服务器
从他们的支持页面
https://support.godaddy.com/help/article/899/how-do-i-use-mod_rewrite
我知道它可以从.htaccess
中完成
所以我在/public_html/mypages/
上加了一个.htaccess
http://www.chrisabernethy.com/force-lower-case-urls-with-mod_rewrite/
这是我的.htaccess文件的内容
RewriteEngine On
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
之后,当我尝试访问任何文件www.myurl.com/Mypages/Page1.php
时,它会出现内部服务器错误。请帮我解决这个问题。
我还尝试添加
<IfModule mod_speling.c>
CheckSpelling On
CheckCaseOnly On
</IfModule>
现在我没有得到内部服务器错误,但我得到了
"找不到文件错误"
www.myurl.com/mypages/page1.php-->运行良好。但是www.myurl.com/mypages/Page1.php-->"找不到文件错误"
如果可以加载mod_speling模块。使用这个:
RewriteEngine On
AllowOverride All
CheckSpelling on
否则;如果你不能(你无法控制它)强制使用mod_rewrite的小写URL(就像你在问题上写的那样)
RewriteEngine On
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
由于.htaccess位于文件夹中,现在位于文档根目录(public_html)中,请尝试添加重写。也许这只是一个问题,因为它不在文档根目录中。
为了解决这个问题,我将所有文件名都改为小写,并在.htaccess中添加了以下内容
RewriteCond %{REQUEST_URI} !([A-Z]+)
RewriteRule .* - [S=27]
RewriteRule ^(.*)A(.*)$ http://%{HTTP_HOST}/$1a$2 [R=301,L]
RewriteRule ^(.*)B(.*)$ http://%{HTTP_HOST}/$1b$2 [R=301,L]
RewriteRule ^(.*)C(.*)$ http://%{HTTP_HOST}/$1c$2 [R=301,L]
RewriteRule ^(.*)D(.*)$ http://%{HTTP_HOST}/$1d$2 [R=301,L]
RewriteRule ^(.*)E(.*)$ http://%{HTTP_HOST}/$1e$2 [R=301,L]
RewriteRule ^(.*)F(.*)$ http://%{HTTP_HOST}/$1f$2 [R=301,L]
RewriteRule ^(.*)G(.*)$ http://%{HTTP_HOST}/$1g$2 [R=301,L]
RewriteRule ^(.*)H(.*)$ http://%{HTTP_HOST}/$1h$2 [R=301,L]
RewriteRule ^(.*)I(.*)$ http://%{HTTP_HOST}/$1i$2 [R=301,L]
RewriteRule ^(.*)J(.*)$ http://%{HTTP_HOST}/$1j$2 [R=301,L]
RewriteRule ^(.*)K(.*)$ http://%{HTTP_HOST}/$1k$2 [R=301,L]
RewriteRule ^(.*)L(.*)$ http://%{HTTP_HOST}/$1l$2 [R=301,L]
RewriteRule ^(.*)M(.*)$ http://%{HTTP_HOST}/$1m$2 [R=301,L]
RewriteRule ^(.*)N(.*)$ http://%{HTTP_HOST}/$1n$2 [R=301,L]
RewriteRule ^(.*)O(.*)$ http://%{HTTP_HOST}/$1o$2 [R=301,L]
RewriteRule ^(.*)P(.*)$ http://%{HTTP_HOST}/$1p$2 [R=301,L]
RewriteRule ^(.*)Q(.*)$ http://%{HTTP_HOST}/$1q$2 [R=301,L]
RewriteRule ^(.*)R(.*)$ http://%{HTTP_HOST}/$1r$2 [R=301,L]
RewriteRule ^(.*)S(.*)$ http://%{HTTP_HOST}/$1s$2 [R=301,L]
RewriteRule ^(.*)T(.*)$ http://%{HTTP_HOST}/$1t$2 [R=301,L]
RewriteRule ^(.*)U(.*)$ http://%{HTTP_HOST}/$1u$2 [R=301,L]
RewriteRule ^(.*)V(.*)$ http://%{HTTP_HOST}/$1v$2 [R=301,L]
RewriteRule ^(.*)W(.*)$ http://%{HTTP_HOST}/$1w$2 [R=301,L]
RewriteRule ^(.*)X(.*)$ http://%{HTTP_HOST}/$1x$2 [R=301,L]
RewriteRule ^(.*)Y(.*)$ http://%{HTTP_HOST}/$1y$2 [R=301,L]
RewriteRule ^(.*)Z(.*)$ http://%{HTTP_HOST}/$1z$2 [R=301,L]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
现在我没有看到任何错误,它接受请求,不管情况如何。