我应该在现有规则中添加什么 RewriteRule 来解决这个问题?
What RewriteRule shall I add to my existing rules to fix this?
我的页面有 2 种语言(不久的将来会是 3 种)。它的内页结构是这样的:
domain.com/en/page (where page is page.php in main root)
并且可以通过domain.com
或domain.com/en/
访问主页
在我的服务器中,我的主根目录中有所有文件,还有一个名为 articles 的文件夹,里面还有一些其他文件。
当我访问像domain.com/en/articles
这样的文件夹文章索引时就可以了。
但是当我像 domain.com/articles
一样访问它时,它会将我带到 404 页面。
我如何打开该文件夹前面没有 /en/
或 /el/
的文件夹?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en|el)/articles$ articles/index.php?lang= [NC]
RewriteRule ^(en|el)(/)?$ index.php?lang= [NC,L]
RewriteRule ^(en|el)/(.*)?$ .php?lang= [NC,L]
RewriteRule ^([^\.]+)$ .php [NC,L]
此外,因为我是 htaccess 的新手,请查看我的整体代码并告诉我任何改进。
你可以有这样的规则:
RewriteRule ^articles/?$ articles/index.php [NC,L]
RewriteRule ^(en|el)/articles$ articles/index.php?lang= [NC,L,QSA]
RewriteRule ^(en|el)/?$ index.php?lang= [NC,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en|el)/(.+)$ .php?lang= [NC,L,QSA]
我的页面有 2 种语言(不久的将来会是 3 种)。它的内页结构是这样的:
domain.com/en/page (where page is page.php in main root)
并且可以通过domain.com
或domain.com/en/
在我的服务器中,我的主根目录中有所有文件,还有一个名为 articles 的文件夹,里面还有一些其他文件。
当我访问像domain.com/en/articles
这样的文件夹文章索引时就可以了。
但是当我像 domain.com/articles
一样访问它时,它会将我带到 404 页面。
我如何打开该文件夹前面没有 /en/
或 /el/
的文件夹?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en|el)/articles$ articles/index.php?lang= [NC]
RewriteRule ^(en|el)(/)?$ index.php?lang= [NC,L]
RewriteRule ^(en|el)/(.*)?$ .php?lang= [NC,L]
RewriteRule ^([^\.]+)$ .php [NC,L]
此外,因为我是 htaccess 的新手,请查看我的整体代码并告诉我任何改进。
你可以有这样的规则:
RewriteRule ^articles/?$ articles/index.php [NC,L]
RewriteRule ^(en|el)/articles$ articles/index.php?lang= [NC,L,QSA]
RewriteRule ^(en|el)/?$ index.php?lang= [NC,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en|el)/(.+)$ .php?lang= [NC,L,QSA]