【发布时间】:2018-01-02 03:40:19
【问题描述】:
如何用htaccess控制url页面并在index页面中获取参数但url中不显示“index”,例如:
1)mydomain is "papashop.com"
2).htaccess :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/?$ $1.php?var1=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ $1.php?var1=$2&var2=$3 [L,QSA]
3)code at contact.php :
<a href="page-alfa">Page Alfa</a> ==> www.papashop.com/page-alfa
4)code at index.php :
<?php
$idpage=$_GET['var1'];
if($idpage != ''){
echo 'show content from query string url';
}else{
echo 'content normal from index web';
}
?>
注意:
1)true: papashop.com/page-alfa => 不工作/找不到页面。 (我想要这个)
2)false: papashop.com/index/page-alfa => 这是我在 index.php 中的代码(但我不想这样)
3)我没有 page-alfa.php 文件,在控制面板中只有 index.php 和 contact.php。
谢谢
【问题讨论】: