Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-12-07 11:51:38

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Add custom RewriteRule to hide $_GET var from url?

I have site (on TXP :) ) which uses FAQ technic based on comments. If you go to this url you can see all comments assigned to article ask-urolog, and on this url you can see comment #162, selected by ?vopros. Inside article i placed some code:

<txp:smd_if field="urlvar:vopros" operator="ge" value="1" filter="/[^0-9]+/" debug="0">
    <!-- select also comment parent to comment_id used in url via urlvar:vopros-->
    <txp:variable name="where" value='discussid={smd_if_vopros} OR parent_comment={smd_if_vopros}' />
    <txp:variable name="order" value="posted asc" />
<txp:else />
    <txp:variable name="where" value='parentid=<txp:article_id /> AND is_answer=0 AND parent_comment=0' />
    <txp:variable name="order" value="posted desc" />
</txp:smd_if>    	

<txp:smd_query debug="0" query = ' 
  SELECT * from uro_txp_discuss 
  WHERE (<txp:variable name="where" />) AND is_answer=0
  ORDER BY <txp:variable name="order" />
' form="vopros-otvet"/>

If explain code in two words – it looks for urlvar vopros, and if it’s set, it searches for requered comment (by lookng for discussid field in txp_discuss table). Otherwise, if no urlvar is set it output all comments.

I want to hide ugle get param from url and use url http://uromax.ru/vopros-otvet/ask-urolog/162 instead of http://uromax.ru/vopros-otvet/ask-urolog?vopros=162.

If I understand RewriteRul technology right, the string should look like this:
RewriteRule ^(.*)vopros-otvet/(.*)/([0-9]+)$ $1vopros-otvet/$2?vopros=$3

I got this .htaccess file:

#DirectoryIndex index.php index.html
#Options +FollowSymLinks
Options -Indexes
<IfModule mod_rewrite.c>
	RewriteEngine On
	#RewriteBase /
	RewriteCond %{REQUEST_FILENAME} -f [OR]
	RewriteCond %{REQUEST_FILENAME} -d
	#RewriteRule ^(.*)vopros-otvet/(.*)/([0-9]+)$ $1vopros-otvet/$2?vopros=$3
	RewriteRule ^(.+) - [PT,L]
	RewriteRule ^(.*) index.php
</IfModule>

In such way after visiting url http://uromax.ru/vopros-otvet/ask-urolog/162 I got 404 page from my hosting provider, not Textpattern’s and this string in error_log:
[Mon Dec 7 14:45:45 2009] [error] [client 91.187.16.235] File does not exist: /home/u78707/uromax.ru/www/vopros-otvet/ask-urolog/162

What i should to change for super-clean-urls? :)


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#2 2009-12-07 21:13:03

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: Add custom RewriteRule to hide $_GET var from url?

Sarah thanks! Folowed links and found some thoughts. Solved (partly) with this .htacces:

#DirectoryIndex index.php index.html
Options +FollowSymLinks
Options -Indexes
<IfModule mod_rewrite.c>
	RewriteEngine On
	#RewriteBase /
	RewriteRule ^(.*)/v([0-9]+)/?$ $1?vopros=$2
	RewriteCond %{REQUEST_FILENAME} -f [OR]
	RewriteCond %{REQUEST_FILENAME} -d
	RewriteRule ^(.+) - [PT,L]
	RewriteRule ^(.*) index.php
</IfModule>

Will look into it deeper…


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

Board footer

Powered by FluxBB