htaccess实现stackoverflow之类的链接

时间:2013-01-29 12:29:55

标签: php .htaccess

  

可能重复:
  how to write a .htaccess redirect like stackoverflow does for its questions

说我的页面链接就像这样......

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

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

根据你的链接修改我认为你想在核心的php文件中制作SEO freindly 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中,我们检查了页面的请求或网址,并根据它我们可以调用所需的文件或操作[通过提取查询字符串]。

愿这会帮到你