Php 如何使用.htaccess中的重写规则更改URL?

Php 如何使用.htaccess中的重写规则更改URL?,php,.htaccess,Php,.htaccess,我有这样的URL: http://example.com/directory/index.php?q=anything 因此PHP将使用$\u GET['q']加载测试变量 我希望在我的.htaccess中简化这一点: http://example.com/directory/anything.html 我该怎么做呢?也许你可以在.htaccess RewriteEngine on RewriteRule ([0-9A-Za-z-\+._]+)\.html$ ./index.php?q=

我有这样的URL:

http://example.com/directory/index.php?q=anything 
因此PHP将使用$\u GET['q']加载测试变量

我希望在我的.htaccess中简化这一点:

http://example.com/directory/anything.html

我该怎么做呢?

也许你可以在
.htaccess

RewriteEngine on

RewriteRule ([0-9A-Za-z-\+._]+)\.html$ ./index.php?q=$1

我要自己解决这个问题:: 这是.htaccess代码

RewriteEngine On
RewriteRule ^directory/([^/]*)\.html$ /directory/index.php?q=$1 [L]

有一个类似的问题可能对你有一些价值。你用的是什么框架?我用的是PHP,可以做
http://example.com/directory/anything
到我的Url。它是否影响我的搜索引擎优化。我想做
http://example.com/directory/anything.html
也就是说,在每个url的末尾添加后缀。以上两种方法同时进行,是否有解决方案?