-1

可能重复:
如何像 stackoverflow 那样编写 .htaccess 重定向来解决它的问题

说我页面的链接是这样的......

http://example.com/test.php?id=10978&name=html-tutorial-for-beginners

我怎样才能做到

http://example.com/10978/html-tutorial-for-beginners

我有多个页面,例如

http://example.com/more_test.php?id=1054758&name=how-to-use-htaccess

http://example.com/some_more_test.php?id=10324758&name=some-thing-good

另外我如何从表单或锚标签发布?

是不是像 action="http://example.com/test.php?id=10978&name=html-tutorial-for-beginners"

或 action="http://example.com/10978/html-tutorial-for-beginners"

对于锚标签 href="http://example.com/test.php?id=10978&name=html-tutorial-for-beginners"

或 href="http://example.com/10978/html-tutorial-for-beginners"

我如何为 test.php、more_test.php some_more_test.php 等多个文件实现它

谢谢您的帮助 !

4

1 回答 1

0

根据您的链接修改,我认为您希望在核心 php 文件中创建 SEO 友好的 url。基本上它会在 MVC 框架中。

但在代码php中仍然不是不可能的

第一步 创建 index.php 文件或任何其他将在每次页面调用时指向的文件 创建 .htaccess 文件,其中将定义任何页面调用请求的规则。下面是 .htaccess 文件代码

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

在 index.php 中,我们检查了页面的请求或 url,基于它我们可以调用所需的文件或操作 [通过提取查询字符串]。

愿这对你有帮助

于 2013-01-29T13:12:55.090 回答