Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的 .htaccess 中有一个干净的 url 重写函数,它工作正常,除非链接中有一个“-”,例如 my-pages.php。我需要知道如何将其作为条件添加到:
RewriteRule ^([a-zA-Z0-9]+)/?$ $1.php
只需在角色类的开头或结尾添加一个破折号:
RewriteRule ^([a-zA-Z0-9-]+)/?$ $1.php
如果在字符类的开头或结尾添加破折号,则不会将其视为特殊字符。
我会使用非贪婪.*来捕捉任何可能的斜线:
.*
RewriteRule ^(.*?)\/?$ $1.php