没有参数的URL,但PHP获取参数(.htaccess?)

时间:2015-02-17 10:55:51

标签: php .htaccess url mod-rewrite redirect

(抱歉我的英语不好。我来自德国)

我正在尝试为Imageviewer获取不错的网址。

我刚获得子域名的htaccess-Code

RewriteEngine on
RewriteCond %{HTTP_HOST} i.domain.de$
RewriteCond %{REQUEST_URI} !^/imageviewer
RewriteRule ^(.*)$ /imageviewer/$1 [L] 

这就是我希望看到的结果。如果我导航到i.domain.de,浏览器会显示正确的URL,并显示/ imageviewer /中的index.php。

但我想要很好的网址。现在我的网址包含 i.domain.de/?id=2ntxfi i.domain.de/index.php?id=2ntxfi 等参数 但我希望它是 i.domain.de/2ntxfi / PHP仍然应该获得$ _GET ['id']参数。

我怎样才能做到这一点?

旁注:我有一个vServer。因此,如果需要,我可以安装Apache扩展。

1 个答案:

答案 0 :(得分:0)

创建一个名为/imageviewer/.htaccess的文件,并输入以下代码:

RewriteEngine On
RewriteBase /imageviewer/

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) index.php?id=$1 [L,QSA]