我知道有很多重写的主题,但我不能得到它。所以我尝试用htaccess重写url。但是我对重写规则不是很了解,所以我想请你帮忙。
重写index.php到root(有效)。
www.example.com/index.php ---> www.example.com
RewriteRule ^(.*)index\.(php|html?)$ /$1 [R=301,NC,L]
重写index.php到根目录后,我的动态网址由这个改成了这个
https://example.com/index.php?baslik=dynamic-slug-url
对此
https://example.com/?baslik=dynamic-slug-url
Php代码(fetch等)工作正常,没有问题。但我想改成这样(我试过动态url重写生成器,但没有结果)。
https://example.com/dynamic-slug-url
在做完上面的事情后,我想改点别的东西。从这个。
https://example.com/specificfile.php?target=dynamicid
改成这样
https://example.com/dynamicid
当它成为上层事物时。
https://example.com/specificfile.php?target=dynamicid&baslik=dynamic-slug-url
将是
https://example.com/dynamicid&baslik=dynamic-slug-url
但我想这样
https://example.com/dynamicid/dynamic-slug-url
我希望我把我的问题和其他事情说清楚。我试过丢失url重写生成器,但无法得到任何结果。谢谢你的回答和良好的解释。
我用这个问题作为自己的一个小练习,这是我想出来的。
# 1) from https://example.com/index.php?baslik=dynamic-slug-url
# to https://example.com/dynamic-slug-url
# and
# 2) from https://example.com/specificfile.php?target=dynamicid
# to https://example.com/dynamicid
RewriteCond %{QUERY_STRING} ^(baslik|target)=([^/.&]+)$
RewriteRule ^(.*)(index|specificfile)\.(php|html?)$ https://example.com/%2? [R=301,L]
# 3) from https://example.com/specificfile.php?target=dynamicid&baslik=dynamic-slug-url
# to https://example.com/dynamicid/dynamic-slug-url
RewriteCond %{QUERY_STRING} ^target=([^/.&]+)&baslik=([^/.&]+)$
RewriteRule ^(.*)(index|specificfile)\.(php|html?)$ https://example.com/%1/%2? [R=301,L]