目前我的链接如下:
http://config.website.nl/?显示=回家我想让它看起来像这样:http://config.website.nl/Home
现在我一直在看很多RewriteEngine脚本,但他们都更先进,我似乎没有得到它的工作…
这是我当前的代码:
RewriteEngine On
# RewriteBase /
RewriteCond %{HTTP_HOST} ^www'.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
RewriteRule ^/(.*)/ index.php?show=$1
让你的。htaccess像这样:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www'.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{THE_REQUEST} 's/+(?:index'.php)?'?show=([^'s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?show=$1 [L,QSA]
给你:
. htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (.*) index.php?show=$1
index . php
<?php
$show = (isset($_REQUEST['show'])) ? strtolower($_REQUEST['show']) : null;
print_r($_REQUEST);
switch ($show) {
case "about":
echo 'About us... <a href="/home">Go back home</a>';
break;
case "home":
default:
echo 'Welcome to the home page... <a href="/about">Visit the about us page</a>';
break;
}
?>
小心:很多人认为。htaccess会"自动"将你写的所有链接从index.php?show=about
变成/about
。事实并非如此。你必须手动配置PHP以正确的格式回显链接(见上文)。
注。根据服务器的不同,您可能需要,也可能不需要RewriteBase行。这就是为什么你会在几个例子中看到它被注释掉了。
我想你只是有一个额外的斜杠在你的最后重写规则。试一试:
RewriteRule ^/(.*) index.php?show=$1