Мод rewrite и странициране

C++ JAVA
Post Reply
Pro_Lamer4e
Нов
Нов
Posts: 188
Joined: Mon Oct 26, 2009 5:10 am

Мод rewrite и странициране

Post by Pro_Lamer4e » Mon Aug 06, 2018 8:26 am

здравейте отново, каде бъркам с Mod rewrite и страницирането
когато напиша servers.php?game=cs&page=2 всичко си работи както трябва, но когато напи6а game/cs/page/2 не зарежда страницата

Code: Select all

RewriteRule ^game/([0-9a-z_]+)/page/([0-9]+)/$ servers.php?id=servers&game=$1&page=$1 [L]
и страницирането

Code: Select all

$query = "SELECT COUNT(server_game) AS numrows FROM amx_servers WHERE server_game='$game'";
$result = mysql_query($query) or die('da');
$row = @mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$br);
$self = $_SERVER['PHP_SELF'];
$ns = '';
for&#40;$page = 1; $page <= $maxPage; $page++&#41; &#123;
if &#40;$page == $pageNum&#41; &#123;
$ns .= "<a class=\"number current\" href=\"$self?game=$game&page=$page\">  $page </a> &nbsp;"; 
&#125;
else &#123;
$ns .= " <a class=\"number \" href=\"$self?game=$game&page=$page\"   >$page</a> ";
&#125;&#125;
if &#40;$pageNum > 1&#41; &#123;
$page = $pageNum - 1;
$pr = " <a href=\"$self?game=$game&page=$page\"   >&laquo; <<< </a> &nbsp;";
$one = " <a href=\"$self?game=$game&page=1\" >&laquo; $site_lang&#91;lastpageone&#93;</a>  ";
&#125;
else &#123;
$pr = ' ';
$one = ' ';
&#125;
if &#40;$pageNum < $maxPage&#41; &#123;
$page = $pageNum + 1;
$sl = " <a href=\"$self?game=$game&page=$page\"  id=\"page\"> >>> </a>  &nbsp;"; 
$pl = &#40;" <a href=\"$self?game=$game&page=$maxPage\" >$site_lang&#91;lastpageserv&#93; &raquo;</a> "&#41;;
&#125;
else &#123;
$sl = '';
$pl = '';
&#125;
echo $one . $ns .  $pl;

User avatar
teroristd
Много Редовен
Много Редовен
Posts: 1769
Joined: Thu Feb 18, 2010 11:50 am
Answers: 83

Post by teroristd » Mon Aug 06, 2018 10:03 am

Така?

Code: Select all

RewriteRule /game/&#40;.*&#41;/page/&#40;.*&#41;/ ?game=$1&page=$2

Pro_Lamer4e
Нов
Нов
Posts: 188
Joined: Mon Oct 26, 2009 5:10 am

Post by Pro_Lamer4e » Mon Aug 06, 2018 12:13 pm

teroristd wrote:Така?

Code: Select all

RewriteRule /game/&#40;.*&#41;/page/&#40;.*&#41;/ ?game=$1&page=$2
не, директно като настина на страница 2 и си пише "servers.php?game=cs&page=2"

User avatar
teroristd
Много Редовен
Много Редовен
Posts: 1769
Joined: Thu Feb 18, 2010 11:50 am
Answers: 83

Post by teroristd » Mon Aug 06, 2018 1:14 pm

Пробвай така.

Code: Select all

RewriteRule /game/&#40;.*&#41;/page/&#40;.*&#41;/ ?game=$1&page=$2 &#91;L,QSA&#93;
Също така кажи работи ли ако го напишеш в браузъра? Кеша изчисти ли?

Pro_Lamer4e
Нов
Нов
Posts: 188
Joined: Mon Oct 26, 2009 5:10 am

Post by Pro_Lamer4e » Mon Aug 06, 2018 1:40 pm

teroristd wrote:Пробвай така.

Code: Select all

RewriteRule /game/&#40;.*&#41;/page/&#40;.*&#41;/ ?game=$1&page=$2 &#91;L,QSA&#93;
Също така кажи работи ли ако го напишеш в браузъра? Кеша изчисти ли?
The requested URL /game/cs/page/1 was not found on this server.
да чиста го кеша

User avatar
teroristd
Много Редовен
Много Редовен
Posts: 1769
Joined: Thu Feb 18, 2010 11:50 am
Answers: 83

Post by teroristd » Mon Aug 06, 2018 2:03 pm

Друго не ми хрумва е че трябва htaccess-a да е в същата папка където е server.php, иначе трябва да се добави и неговото име в условието.

Code: Select all

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteRule /game/&#40;.*&#41;/page/&#40;.*&#41;/ ?game=$1&page=$2 &#91;L,QSA&#93; 

User avatar
anonimen
Web-tourist
Web-tourist
Posts: 1534
Joined: Mon Jun 11, 2012 6:07 pm
Answers: 163
Location: Parse error: unexpected "}" in /home/index.php on line 26

Post by anonimen » Mon Aug 06, 2018 5:57 pm

Pro_Lamer4e wrote:
teroristd wrote:Пробвай така.

Code: Select all

RewriteRule /game/&#40;.*&#41;/page/&#40;.*&#41;/ ?game=$1&page=$2 &#91;L,QSA&#93;
Също така кажи работи ли ако го напишеш в браузъра? Кеша изчисти ли?
The requested URL /game/cs/page/1 was not found on this server.
да чиста го кеша
Teroristd правилно ти го е дал, това не тръгва само заради крайната наклонена черта:
The requested URL /game/cs/page/1 was not found

RewriteRule /game/(.*)/page/(.*)/ ?game=$1&page=$2
Regex-ът завършва на "/", затова и матчва само ако урл-то завършва на "/"

User avatar
teroristd
Много Редовен
Много Редовен
Posts: 1769
Joined: Thu Feb 18, 2010 11:50 am
Answers: 83

Post by teroristd » Tue Aug 07, 2018 6:09 am

anonimen wrote:Regex-ът завършва на "/", затова и матчва само ако урл-то завършва на "/"
Изобщо не се сетих за това и почвам да търся проблема къде ли не другаде :D.

Pro_Lamer4e
Нов
Нов
Posts: 188
Joined: Mon Oct 26, 2009 5:10 am

Post by Pro_Lamer4e » Tue Aug 07, 2018 7:35 am

anonimen wrote:
Pro_Lamer4e wrote:
teroristd wrote:Пробвай така.

Code: Select all

RewriteRule /game/&#40;.*&#41;/page/&#40;.*&#41;/ ?game=$1&page=$2 &#91;L,QSA&#93;
Също така кажи работи ли ако го напишеш в браузъра? Кеша изчисти ли?
The requested URL /game/cs/page/1 was not found on this server.
да чиста го кеша
Teroristd правилно ти го е дал, това не тръгва само заради крайната наклонена черта:
The requested URL /game/cs/page/1 was not found

RewriteRule /game/(.*)/page/(.*)/ ?game=$1&page=$2
Regex-ът завършва на "/", затова и матчва само ако урл-то завършва на "/"
добре, но пак не става

Code: Select all

Not Found
The requested URL /game/cs/page/1/ was not found on this server.
а това е .htaccess

Code: Select all

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^server-&#40;&#91;0-9&#93;+&#41;&web$ serv.php?id=info&serv=$1&web=$1 &#91;NE&#93;
RewriteRule ^server-&#40;&#91;0-9&#93;+&#41;&players$ serv.php?id=info&serv=$1&players=$1 &#91;NE&#93;
RewriteRule ^server-&#40;&#91;0-9&#93;+&#41;&rankchart$ serv.php?id=info&serv=$1&rankchart=$1 &#91;NE&#93;
RewriteRule ^server-&#40;&#91;0-9&#93;+&#41;&rules$ serv.php?id=info&serv=$1&rules=$1 &#91;NE&#93;
RewriteRule /game/&#40;.*&#41;/page/&#40;.*&#41;/ ?game=$1&page=$1 &#91;L,QSA&#93;
едит: оправих се благодаря и на двама ви но точката ще е за терорист.
ето по този начин всичко ми работи идялно

Code: Select all

RewriteRule ^game/&#40;&#91;0-9a-z_&#93;+&#41;/page/&#40;&#91;0-9&#93;+&#41;/$ servers.php?game=1&page=$2  &#91;L&#93;
и страницирането

Code: Select all

$query = "SELECT COUNT&#40;server_game&#41; AS numrows FROM amx_servers WHERE server_game='$game'";
$result = mysql_query&#40;$query&#41; or die&#40;'da'&#41;;
$row = @mysql_fetch_array&#40;$result, MYSQL_ASSOC&#41;;
$numrows = $row&#91;'numrows'&#93;;
$maxPage = ceil&#40;$numrows/$br&#41;;
$self = $_SERVER&#91;'PHP_SELF'&#93;;
$ns = '';
for&#40;$page = 1; $page <= $maxPage; $page++&#41; &#123;
if &#40;$page == $pageNum&#41; &#123;
$ns .= "<a class="number current" href="/game/$game/page/$page/">  $page </a> &nbsp;"; 
&#125;
else &#123;
$ns .= " <a class="number " href="/game/$game/page/$page/"   >$page</a> ";
&#125;&#125;
if &#40;$pageNum > 1&#41; &#123;
$page = $pageNum - 1;
$pr = " <a href="/game/$game/page/$page/"   >&laquo; <<< </a> &nbsp;";
$one = " <a href="/game/$game/page/1/" >&laquo; $site_lang&#91;lastpageone&#93;</a>  ";
&#125;
else &#123;
$pr = ' ';
$one = ' ';
&#125;
if &#40;$pageNum < $maxPage&#41; &#123;
$page = $pageNum + 1;
$sl = " <a href="$self?game=$game&page=$page"  id="page"> >>> </a>  &nbsp;"; 
$pl = &#40;" <a href="$self?game=$game&page=$maxPage" >$site_lang&#91;lastpageserv&#93; &raquo;</a> "&#41;;
&#125;
else &#123;
$sl = '';
$pl = '';
&#125;
echo $one . $ns .  $pl;

Post Reply