我有以下网址
str.format
我想使用.htaccess使其类似于以下内容
http://localhost/apps/site/index.php?lang=es
http://localhost/apps/site/es
当我尝试使用此网址<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+?)/?$ /index.php?lang=$1 [L,QSA]
</IfModule>
时
直接将我重定向到http://localhost/apps/site/es
我已经尝试过此解决方案,但不适用于我:
答案 0 :(得分:0)
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/apps/site/index.php$
RewriteCond %{QUERY_STRING} ^lang=(\w+)
RewriteRule apps/site/index.php /apps/site/%1 [QSD,L]
第一个条件是告诉模块仅在请求URI恰好/apps/site/index.php
第二个条件,如果第一个查询参数名称为lang
并且其值是一个单词。 ()
将捕获参数的值并将其保存在%1
在规则中,我们告诉模块删除apps/site/index.php
并用/apps/site/%1
重写,同时用我们从第二个条件捕获的值替换%1
QSD
查询字符串丢弃标志是为了使模块不将查询附加到最终URL(必须在L
标志之前进行设置,这将不 >工作[L,QSD]
)
现在,如果您要求
http://localhost/apps/site/index.php?lang=es
它将被重写为
http://localhost/apps/site/es
您可以在此网站https://htaccess.madewithlove.be/上测试并尝试使用重写规则