URL rewriting via Wordpress Rewrite or .htaccess -
jump edit8 see how solved this
let's have wordpress blog: www.animals.com
. have php file in theme directory: www.animals.com/wp-content/themes/mytheme/db.php
. also, have custom template page, create new page in wordpress administration panel show db.php
: www.animals.com/database
.
so if want read lions, go to: www.animals.com/database/?animal=lion
(because that's way decided write php, inserting value $_get['animal'] query, using pdo etc.).
now, access www.animals.com/database/?animal=lion
www.animals.com/lion
.
should use .htaccess or wordpress rewrite? should place .htaccess, in root of wordpress folder (with wp-config.php , files) or in theme directory?
the 1 root has rewritebase /
, stuff wordpress default. should write achieve want? should put before or after existing code?
edit: public_html .htaccess , really want do: have website: www.domain.com
, when type http://www.domain.com/dios/?dios=agni
shows info god agni. type www.domain.com/dioses/agni
access info god agni. php file in www.domain.com/wp-content/themes/smitespain/dios.php
it's not working x_x
# begin wordpress <ifmodule mod_rewrite.c> rewriteengine on rewritebase / rewriterule ^dioses/(\w*)$ dios/?dios=$1 [nc,l] rewriterule ^index\.php$ - [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule . /index.php [l] </ifmodule> # end wordpress
edit2: i'm using multisite (check edit4), , again, /database/ /dios/ , /dioses/ not actual folders created, thats name page created in wordpress. thing is, shows name of god in tab title :s means variable $_get['dios'] set, doesnt load file (dios.php) =/
edit3: need access domain.com/dios/?dios=agni specifically, because thats url let php file (dios.php) load get_header() wordpress, cant access file directly
edit4: decided remove multisite thing
edit5: these wordpress pages have: domain.com/dioses/
(www.domain.com/wp-content/themes/smitespain/dioses.php)
domain.com/dios/?dios=thor
(www.domain.com/wp-content/themes/smitespain/dios.php)
edit6: reading in wordpress codex..and realized that, if wanna go domain.com/dioses
can access going domain.com/index.php?pagename=dioses
or domain.com/?pagename=dioses
so, added between rewritebase /
, next rule: rewriterule example/test ?pagename=dioses
, domain.com/example/test
redirects me domain.com/dioses
changes url in address bar :(
thing is, if try this: rewriterule example/test ?pagename=dios&dios=thor
send me page 'dios' without '?dios=thor'
edit7: started using wordpress rewrite, added theme's functions.php:
function my_rewrite_rules() { add_rewrite_rule( 'blah', 'index.php?pagename=dios&dios=agni', 'top' ); } add_action( 'init', 'my_rewrite_rules' );
and again..it loads page dios, without ?dios=agni
edit8: , finally, managed make work =)
first thing needed know is, new ?dios=xxxx
no longer available $_get['dios']
instead, need call $wp_query->query_vars['dios']
added theme's functions.php
function add_query_vars($new_var) { $new_var[] = "dios"; return $new_var; } add_filter('query_vars', 'add_query_vars'); function add_rewrite_rules($rules) { $new_rules = array('([^/]+)' => 'index.php?pagename=dios&dios=$matches[1]'); $rules = $new_rules + $rules; return $rules; } add_filter('rewrite_rules_array', 'add_rewrite_rules');
i make sure $wp_query->query_vars['dios']
set
add regular rule
there way solve it, without touching wordpress.
add .htaccess
rewriterule ^lion /indexw.php?pagename=db&dios=$1 [l,e=uri:/detail/]
create file indexw.php:
<?php $_server["request_uri"] = $_server["redirect_uri"]; include("index.php");
how works? mod_rewrite sets redirect_uri specified in e=uri:value argument. indexw.php overwrites request_uri correct value (thanks ravi thapliyal insight on this)
Comments
Post a Comment