【发布时间】:2022-02-06 07:46:25
【问题描述】:
有几篇关于此的文章,但我无法使其发挥作用。
我有以下网址:
1. /index.php
2. /index.php?lg=el
3. /index.php?lg=en
4. /index.php?lg=el#anchor
5. /index.php?lg=en#anchor
6. /index.php?ct=1&lg=el
7. /index.php?ct=1&lg=el#anchor
8. /index.php?ct=1&lg=en
9. /index.php?ct=1&lg=en#anchor
10. /index.php?ct=2&lg=el
11. /index.php?ct=2&lg=el#anchor
12. /index.php?ct=3&lg=el
13. /index.php?ct=3&lg=el#anchor
14. /index.php?ct=4&lg=el
15. /index.php?ct=4&lg=el#anchor
16. /index.php?ct=5&lg=el
17. /index.php?ct=5&lg=el#anchor
18. /index.php?ct=2&lg=en
19. /index.php?ct=2&lg=en#anchor
20. /index.php?ct=3&lg=en
21. /index.php?ct=3&lg=en#anchor
22. /index.php?ct=4&lg=en
23. /index.php?ct=4&lg=en#anchor
24. /index.php?ct=5&lg=en
25. /index.php?ct=5&lg=en#anchor
和类似的没有“index.php”。 “ct”变量应根据以下数组进行转换(索引从 1 开始):
[company,history,news,measurements,contact]
我想将它们转换为:
1. /
2. /el
3. /en
4. /el#anchor
5. /en#anchor
6. /el/company
7. /el/company#anchor
8. /en/company
9. /en/company#anchor
10. /el/history
11. /el/history#anchor
12. /el/news
13. /el/news#anchor
14. /el/measurements
15. /el/measurements#anchor
16. /el/contact
17. /el/contact#anchor
18. /en/history
19. /en/history#anchor
20. /en/news
21. /en/news#anchor
22. /en/measurements
23. /en/measurements#anchor
24. /en/contact
25. /en/contact#anchor
我在 .htaccess 中尝试了以下语法:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\/)?([a-z]{2})?(\/)?((?:company|history|news|measurements|contact))?(#[\w\-]+)?$ $1index.php?ct=$4&lg=$2$5 [L,QSA]
但我无法得到预期的结果。
有什么想法吗?
【问题讨论】:
标签: apache .htaccess url mod-rewrite url-rewriting