0

我只需要将此 URLwww.mysite.com/index.php?url=othersite.com重写为www.mysite.com/othersite.com

我写了这个.htaccess

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?url=$1

还将该代码添加到.htaccess文件中并与文件一起上传到站点根index.php目录,但无论如何,我总是得到www.mysite.com/index.php?url=othersite.com

非常感谢指教!

4

1 回答 1

0

嗯,就这样解决了。形式

<form method="post" name="downform" action="" onsubmit="return formSubmit()">

JS

function formSubmit() {
  domain = document.getElementById('domain_input').value;
  window.location = '/' + domain;
  return false;
}

.htaccess

Options +FollowSymlinks
RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_.-]+)$ index.php?domain=$1
RewriteRule ^([a-zA-Z0-9_.-]+)/$ index.php?domain=$1

<files .htaccess>
    order allow,deny
    deny from all
</files>

PHP(只是为了看结果)

if($_SERVER['REQUEST_URI']!='/')
    echo trim($_SERVER['REQUEST_URI'],'/');
于 2012-07-13T18:02:17.537 回答