我怎样才能在php中重写子URL:
localhost\edev\pages\UI.php?employee=1
进入这个:
localhost\edev\pages\UI.aspx?employee=1
注意:我已经尝试在我的.htaccess中添加这个:
RewriteEngine on
# Rewrite /foo/bar to /foo/bar.php
RewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L]
# Return 404 if original request is /foo/bar.php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ]*$"
RewriteRule .* - [L,R=404]
# NOTE! FOR APACHE ON WINDOWS: Add [NC] to RewriteCond like this:
# RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$" [NC]
我已经尝试过其他一些答案,但不适合我。谢谢。
你可以使用str_replace
码:
$newUrl = str_replace('php', 'aspx', 'localhost\edev\pages\UI.php?employee=1');
header('Location: ' . $newUrl);