我需要使用htaccess
来做到这一点当针对http://www.example.com/home发出请求时,它应该(内部)加载页面http://www.example.com/home_st.php
同样,当向其他名为产品的链接(http://www.example.com/products)发出请求时,它应该(内部)加载http://www.example.com/products_st.php
简而言之,它正在添加“_st.php”并加载该URL。但我不想要的一件事是,如果用户在浏览器中直接键入http://www.example.com/home_st.php或http://www.example.com/products_st.php,则应显示404 / Page not found错误
我在该文件夹中没有其他几个页面,我希望这些页面以这种方式运行。我理解htaccess应该有这样的东西
P.N:我的网址不应显示实际的文件名,例如home_st.php,products_st.php等。它应该只显示为http://www.example.com/home,http://www.example.com/products等
htaccess和正则表达式不是我熟悉的东西。任何帮助都会很棒。感谢
答案 0 :(得分:2)
您希望能够重写网址
这是之前写的,但我会再说一遍。
您想使用Htaccess文件和重写规则。
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^pet-care/?$ pet_care_info_01_02_2008.php [NC,L] # Handle requests for "pet-care"
这将生成此网址:http://www.pets.com/pet_care_info_07_07_2008.php
看起来像这样:http://www.pets.com/pet-care/
指向更多信息的链接:How to make Clean URLs
以及我过去常用的网页:https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
为了让你的页面按照你想要的方式设置,我建议你阅读两篇文章并试着找到你想要的东西。
如果您需要一些特定的帮助,请询问。
希望有所帮助。