所以,我需要设置自定义的网址,以便用PHP
去:
http://example.com/dynamic.php
我知道这是一个非常简单的操作,但经过一番使用谷歌搜索,我找不到答案。处理这样的事情最简单的方法是什么?
所以,我需要设置自定义的网址,以便用PHP
去:
http://example.com/dynamic.php
我知道这是一个非常简单的操作,但经过一番使用谷歌搜索,我找不到答案。处理这样的事情最简单的方法是什么?
有实现的几种方法这一点: -
RewriteEngine on RewriteRule ^$ dynamic.php
<script type="text/javascript"> window.location = "http://example.com/dynamic.php" </script> <script type="text/javascript"> location.href='http://example.com/dynamic.php'; </script> <script type="text/javascript"> location.replace('http://example.com/dynamic.php'); </script>
However, if using PHP instead (recommended), include the following:-
header("Location: http://example.com/dynamic.php ");
Remember to use ob_start(), ob_end_flush() to fix the output buffer, if you get the error that the headers are already sent and you can't modify the header information.
希望这有助于。
你必须使用url重写来做到这一点。 取决于您正在使用的Web服务器。例如, ,如果您的Web服务器是Apache,则可以使用.htaccess。 Apache URL Rewriting.
为正则表达式将是这样的:
RewriteEngine on
RewriteRule ([^/]+)/?$ $1.php [L]
运行左边的正则表达式将返回“动态/”或“动态”如果不包括正斜杠。然后它将用dynamic.php替换第一个括号内的块(“dynamic /”)中捕获的内容。
你可以试试你的URL重写这里:
在这里,你一般的正则表达式:
也许更好的正则表达式是([^ /] +)/ *?$,因为它将在最后解释多个正斜杠,但我不知道服务器是否将它们保留在那里:P – 2011-01-22 14:47:23
您需要在.htaccess中写入规则 – 2011-01-22 13:31:40
另请参阅http://stackoverflow.com/questions/3631153/how-come-some-site-urls-do-not-include-a-file-extension/3631241#3631241 – Gumbo 2011-01-22 13:44:16