我试图解决一些htaccess的问题,我不能够达成解决方案。 我有以下的html:
I'm trying to solve some htaccess question and I'm not able to reach the solution. I have the following html:
< A HREF =www.site/home.php?Idi=英语>英语< / A> < A HREF =www.site/home.php?Idi=法语>法语< / A>
<a href="www.site/home.php?Idi="English">English</a> <a href="www.site/home.php?Idi="Française">Française</a>
和目标是,用户只要获得其地址栏中输入:
and the goal is that user just gets in its address bar:
www.site/home/English
或
www.site/home/Française
显然,GET变量应该到达home.php进行处理。
Obviously, the get variables should arrive to home.php to be processed.
此外,该网站还有其他页面扩展名为.php然后我删除每个扩展名:
Also, the site has other pages with extension .php and I got delete each extension with:
选项+了FollowSymLinks RewriteEngine叙述上 的RewriteBase / 的RewriteCond%{} REQUEST_FILENAME -f .PHP 重写规则^%{REQUEST_URI}的.php [L]
Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^ %{REQUEST_URI}.php [L]
另外,我想起始页:
www.site/home.php
将显示为:
www.site/home/English
我看到有关它很多的教程和职位,但我不能够解决这个问题。
I have seen a lot of tutorials and posts concerning it, but I am not able to solve it.
任何帮助将是AP preciated,谢谢
Any help would be appreciated, thanks
EDITED 的
EDITED:
最后,UnskilledFreak建议我,我改变了原来的链接:
Finally, as UnskilledFreak suggested me, I changed the original links to:
<a href="www.site/home/English">English</a> <a href="www.site/home/Française">Française</a>和htaccess的是如下:
and the htaccess is as:
Options +FollowSymLinks RewriteEngine on RewriteBase / #Receive site/home/Language and internally processes site/home.php?Idi=Language RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^home/(English)/?$ home.php?Idi=English [QSA,NC,L] RewriteRule ^home/(Française)/?$ home.php?Idi=Française [QSA,NC,L] #Receive site/something and internally goes to site/something.php RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^ %{REQUEST_URI}.php [L]要避免的css,js和在新的页面加载等环节的崩溃,我添加了一个 / 前的HTML的每一条路径。
To avoid the crash of css, js and other links loaded in new pages, I added a / before every path of the html.
.htaccess中被放在根。 在家的文件夹不服务器存在。
The htaccess is placed in the root. The 'home' folder doesn't exist in the server.
推荐答案像注释说明,编辑后的邮政以上,它会工作;)
Like the comments explain AND the edited Post above, it'll work ;)
但这里是另一种解决方案获取和工作过:
but here is another solution i get and works too:
在我的document_root我添加了一个名为测试,在那里我已经得到了4个文件具有以下内容的文件夹:
in my document_root i've added a folder called test, in there i've got 4 files with following content:
的.htaccess
Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . /test/index.php [L]
的index.php - 一个包装重写和testlinks
index.php - a wrapper for rewrite and testlinks
echo' <!DOCTYPE html> <head> <title>Rewrite Test</title> <link rel="stylesheet" type="text/css" href="/test/style.css"> </head> <body> <a href="/test/home/english">English</a><br> <a href="/test/home/francaise">Francaise</a><br> '; $get = explode("/",$_SERVER["REQUEST_URI"]); $get = array_slice($get,2); // ignoring first empty key and folder 'test' #echo "<pre>".print_r($get,true)."</pre>"; if(file_exists($get[0].".php")) require($get[0].".php"); else echo 'file '.$get[0].'not found'; echo' </body> </html>';
home.php - 按要求
<?php echo 'in home.php, you have choosen:'.$get[1]; ?>
的style.css - 仅作为测试文件访问将工作
style.css - only as test that file access will work
body { color:#ff8800; font-weight:bold: }
测试按预期工作:)
tested and works as expected :)
更多推荐
删除GET变量和.PHP使用htaccess的
发布评论