[ASK] How to rewrite url without editing htaccess on wordpress?

pmesco

New member
try this bro :)
ill make it just for you :D

Code:
RewriteEngine On
RewriteBase /
RewriteRule ^(.+)/(.+)$ index.php?type=$1&q=$2
 

ogah

New member
pmesco said:
try this bro :)
ill make it just for you :D

Code:
RewriteEngine On
RewriteBase /
RewriteRule ^(.+)/(.+)$ index.php?type=$1&q=$2

i dont need htaccess since i want easy installation of my plugin.
only click activated both plugins and permalink done.

i have trick get query from request uri
PHP:
if(isset($_GET['q']) AND isset($_GET['type'])) {
$q = $_GET['q'];
$type = $_GET['type']; 
}
if(preg_match('/\/pdf\//', $_SERVER['REQUEST_URI'])) {
$q = end(explode('/', $_SERVER['REQUEST_URI']));
$type = 'pdf';
}
now my plugins have nice permalink :)

but any suggestion about rewrite url using wordpress API are wellcome.

i still need it for more complex variable
 

jaran

New member
Did you try with $_SERVER["PATH_INFO"] ??
PHP:
preg_match('@[/]{1}([a-zA-Z0-9]+)@', $_SERVER["PATH_INFO"], $query);
$query will contain an array of elements, from the example, $query[0] = 'q' and $query[1] = 'type'
 

ogah

New member
jaran said:
Did you try with $_SERVER["PATH_INFO"] ??
PHP:
preg_match('@[/]{1}([a-zA-Z0-9]+)@', $_SERVER["PATH_INFO"], $query);
$query will contain an array of elements, from the example, $query[0] = 'q' and $query[1] = 'type'

its great. i will use it. with this more easily passing the pdf, doc, docx and other path using function if in array.
thanks bro
 

admin

Administrator
Staff member
Great post and responses, it`s the exact type of discussion we are looking for here on Gigarank.
 

jaran

New member
ogah said:
jaran said:
Did you try with $_SERVER["PATH_INFO"] ??
PHP:
preg_match('@[/]{1}([a-zA-Z0-9]+)@', $_SERVER["PATH_INFO"], $query);
$query will contain an array of elements, from the example, $query[0] = 'q' and $query[1] = 'type'

its great. i will use it. with this more easily passing the pdf, doc, docx and other path using function if in array.
thanks bro

Gladly if it was help you. Because I dont tested yet on WP. :D
This is small explain what regex function mean. The part of regex "[/]{1}" is mean result array explode from your url.
So if you wants to use for multi string "/" from your url, you just change number instead of regex.
PHP:
$string = 'hxxp://domain.com/abcd/def/?q=1&type=doc';   
//Regex function is
preg_match('@[/]{2}([a-zA-Z0-9]+)@', $_SERVER["PATH_INFO"], $query);
I hope you understand what I mean. Sorry for my bad english. :D
 

ogah

New member
jaran said:
Did you try with $_SERVER["PATH_INFO"] ??
PHP:
preg_match('@[/]{1}([a-zA-Z0-9]+)@', $_SERVER["PATH_INFO"], $query);
$query will contain an array of elements, from the example, $query[0] = 'q' and $query[1] = 'type'
bad news, PATH_INFO not work in my script.
i get empty string.
PATH_INFO only work if url like this http://mydomain.com/path/file.php/query1/query2
and we will get string with value is after file extension
 

jaran

New member
I guess you need this before using script at above. Place this at the top of header.
PHP:
header("location: http://example.com".preg_replace('#(.php\??)|[=&]#','/',$_SERVER['PHP_SELF']));
It will replace your url to become hxxp://domain.com/abcd/q/salad/type/pdf
 

ogah

New member
jaran said:
I guess you need this before using script at above. Place this at the top of header.
PHP:
header("location: http://example.com".preg_replace('#(.php\??)|[=&]#','/',$_SERVER['PHP_SELF']));
It will replace your url to become hxxp://domain.com/abcd/q/salad/type/pdf

for redirecting i use internal wordpress function wp-redirect and add_action( 'template_redirect', 'redirect-function' );
 

pmesco

New member
ogah said:
jaran said:
I guess you need this before using script at above. Place this at the top of header.
PHP:
header("location: http://example.com".preg_replace('#(.php\??)|[=&]#','/',$_SERVER['PHP_SELF']));
It will replace your url to become hxxp://domain.com/abcd/q/salad/type/pdf

for redirecting i use internal wordpress function wp-redirect and add_action( 'template_redirect', 'redirect-function' );

you should also ask in stackexchange
maybe they can help on your problem :)
 

ogah

New member
this is not a big problem pmesco.
i have found the way to get variable from request uri.
i want to discus to find the simple way to get complex variable from uri.

my plugins that i use in recipes.cf only 1 file with 6 kb size. it work without touch the htaccess file.

and last night i build full web with this plugins with 3 extra files. with total file size of my plugin less than 12 kb.
installation (upload & activated) only do from wp admin dashboard without touching the htaccess
and this is the web that i build http://index.myonlinedocuments.net
 

Genesis

Administrator
Staff member
ogah said:
and last night i build full web with this plugins with 3 extra files. with total file size of my plugin less than 12 kb.
installation (upload & activated) only do from wp admin dashboard without touching the htaccess
and this is the web that i build http://index.myonlinedocuments.net
Pretty amazing .... well done! :cool: