2014-04-29 23 views
1

然後我使用php_self並按下一個按鈕我去index.php,但我想留在我點擊的頁面。htaccess和php_self不工作在同一頁

所以我的.htaccess現在正在尋找這樣的:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /svetaine/ 
RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 
RewriteCond %{REQUEST_URI} ^application.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

我的表分頁代碼是在這裏:

<h1>Skaitmeniniai fotoaparatai</h1> 
<form method='get'> 
<?php 
//check if the starting row variable was passed in the URL or not 
if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) { 
//we give the value of the starting row to 0 because nothing was found in URL 
    $startrow = 0; 
//otherwise we take the value from the URL 
} else { 
$startrow = (int)$_GET['startrow']; 
} 
//this part goes after the checking of the $_GET var 
$fetch = mysql_query("SELECT * FROM sfotoaparatai order by rand() LIMIT $startrow, 20")or 
die(mysql_error()); 
$num=Mysql_num_rows($fetch); 
    if($num>0) 
    { 
    echo "<table border=2 >"; 
    echo "<tr><td>Prekes Pavadinimas</td><td>Kaina</td><td>Parduotuve</td> <td>Nuoroda</td></tr>"; 
    for($i=0;$i<$num;$i++) 
    { 
    $row=mysql_fetch_row($fetch); 
    echo "<tr>"; 
    echo"<td>$row[1]</td>"; 
    echo"<td>$row[2] LT</td>"; 
    echo"<td>$row[3]</td>"; 
    echo "<td><a href=\"{$row[4]}\"><img src=\"".base_url()."images/parduotuve.png\" /></a></td>"; 
    echo"</tr>"; 
    } 
    echo"</table>"; 
    } 
///now this is the link.. 
    echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+5).'">Sekantis</a>'; 

    $prev = $startrow - 5; 

//only print a "Previous" link if a "Next" was clicked 
if ($prev >= 0) 
echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'"> Buves</a>'; 
?> 
</form> 
</body> 

然後我點擊下一個表頁我的鏈接改變爲localhost/svetaine/index.php?startrow = 5,它應該是localhost/svetaine/sfotoaparatai?startrow = 5

+0

你目前面臨的問題是什麼? – anubhava

+0

這是表分頁,這應該是在一個頁面,不想被重定向在index.php – Mangirdas

+0

我看不到在這裏發生重定向?你想在瀏覽器中使用哪個網址? – anubhava

回答

0

有這樣的規則:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /svetaine/ 

RewriteCond %{QUERY_STRING} (^|&)startrow=[0-9] [NC] 
RewriteRule^- [L] 

RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 
RewriteCond %{REQUEST_URI} ^application.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 
+0

相同。也許最好使用REQUEST_URI而不是PHP_SELF。但問題將出現在前一個按鈕中。下一步將正常工作 – Mangirdas

+0

只要存在'startrow = [0-9] +',此規則將避免重寫。 (查看更新) – anubhava

+0

更新問題。也許這是與其他行不與我的表分頁問題?因爲我試過你更新的問題,仍然是問題 – Mangirdas