简体   繁体   English

不需要来自 example.com/{lang}/index.php 的 index.php

[英]Not needing index.php from example.com/{lang}/index.php

My .htaccess currently looks like:我的 .htaccess 目前看起来像:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+([^/]+)/\?lang=([^\s&]+) [NC]
RewriteRule ^ /%2/%1? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z]{2})/([^/]+)/?$ $2/?lang=$1 [L,QSA]

Which means that example.com/{lang}/some-page.php acts as example.com/some-page.php?lang={lang}这意味着example.com/{lang}/some-page.php充当example.com/some-page.php?lang={lang}

Remaining issue: example.com/{lang} does not work unless it has index.php like `example.com/{lang}/index.php剩下的问题: example.com/{lang}不起作用,除非它有index.php像 `example.com/{lang}/index.php

How can I make it work when we go directly to example.com/{lang} ?当我们直接访问example.com/{lang}时,如何使其工作?

How about this:这个怎么样:

RewriteEngine On

RewriteCond %{ENV:REDIRECT_rewritten} !=1
RewriteCond %{QUERY_STRING} ^lang=([a-z]{2})$ [NC]
RewriteRule ^([^/]*)$ /%1/$1? [R=301,L]

RewriteCond %{REQUEST_URI} !^/js/
RewriteRule ^([a-z]{2})(?:/([^/]+))?$ $2?lang=$1 [NC,L,QSA,E=rewritten:1]

I really don't like matching on THE_REQUEST so changed that.我真的不喜欢在 THE_REQUEST 上匹配所以改变了它。 This also redirects just /?lang=xx which you may not want.这也仅重定向了您可能不想要的/?lang=xx I used the same matching for lang strings in both rules which you may not want.我在您可能不想要的两个规则中对 lang 字符串使用了相同的匹配。 Let me know.让我知道。

Not sure you need the file or directory existence checks and it is slowing things down a bit if not necessary, as the filesystem must be polled twice on every request.不确定您是否需要检查文件或目录是否存在,如果没有必要,它会减慢速度,因为每次请求都必须轮询文件系统两次。 Do you have two letter files or directories in root?根目录下是否有两个字母文件或目录?

暂无
暂无

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

相关问题 如何从这个example.com/index.php?lang=en更改我的多语言网址到这个example.com/en/? - How can I change my multilingual urls from this example.com/index.php?lang=en to this example.com/en/? “ example.com/index.php/page/about/”是好的做法吗? - Is “example.com/index.php/page/about/” good practice? 如果网址中没有index.php,example.com / index.php中的首页无法加载 - Home page is not loading without index.php in url, example.com/index.php 将example.com/dashboard.php更改为example.com/index.php?action=dashboard - Change example.com/dashboard.php to example.com/index.php?action=dashboard 是否可以将 example.com/index.php?page=abc 重定向到 example.com/abc? - Is it possible to redirect the example.com/index.php?page=abc to example.com/abc? 如何将example.com/forum/index.php重定向到example.com/forum/ - How to redirect example.com/forum/index.php to example.com/forum/ 使用,htaccess将example.com?id=12重定向到example.com/index.php?id=12 - using ,htaccess redirect example.com?id=12 to example.com/index.php?id=12 如何将example.com/index.php/lib更改为example.com/lib? - How to change example.com/index.php/lib to example.com/lib? Ubuntu-如何直接将example.com/opencart/index.php定向到http://example.com/和www.example.com? - Ubuntu - How direct example.com/opencart/index.php to http://example.com/ and www.example.com? 如何使用.htaccess将http://example.com/test.php设置为http://example.com/index.php?do=test? - How to make http://example.com/test.php to http://example.com/index.php?do=test using .htaccess?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM