i have an URL like this:
http://domain.de/projekte/agbz/userprofile/?page=member&memberID=Z4911331&land=deutschland&fa=zahnarzt&vorname=Henryk&nachname=Donnerstag
I want to rewrite this URL in a structure like this:
https://www.domain.de/deutschland/zahnarzt/dr_michael_claar_kassel_Z4901196/
my rewrite Rule in my functions.php is like that, but its not working:
add_rewrite_rule(
'/agbz\/(\w*)\/\?page=(\w*)&memberID=([a-z]{1}\d*)&land=(\w*)&fa=(\w*)&vorname=(\w*)&nachname=(\w*)/',
'index.php?page_id=$matches[1]&page=member&memberID=$matches[3]&land=$matches[4]&fa=$matches[5]&vorname=$matches[6]&nachname=$matches[7]',
'top');
Can anybody help me at this point?
For example
www.example.com/somePage/products/?mfg=UETD342
to
www.example.com/somePage/products/UETD342/
you can add custom URL tag using below code:
function custom_rewrite_tag() {
add_rewrite_tag('%mfg%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);
and add below code to add your own custom rewrite rule for loading your page with this parameter:
function custom_rewrite_rule() {
add_rewrite_rule('^products/([^/]*)/?','index.php?page_id=your_page_id&mfg=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);
you need to add both codes in your theme's functions.php
For a more detailed knowledge of url rewriting visit: https://codex.wordpress.org/Rewrite_API/add_rewrite_rule
Related
I want to receive a parameter from URL with extension in that.
Here is my controller:
public function actionIndex($directory=null,$filename=null)
{
echo $directory.$filename;exit;
}
Here is my URL rule:
'<directory:\w+>/<filename:\w+>' => 'file/index',
it works like that:
localhost/uploads/abc
But it shows 404 when I do this:
localhost/uploads/abc.pdf
Any suggestions how this can be achieved?
I was able to achieve that with following regex:
'<directory:\w+>/<filename:\w+[.]\w+>' => 'file/index'
I have the current RewriteRule:
RewriteRule ^search/([0-9a-zA-Z-\s-:]+)(/?)$ search.php?search=$1 [NC,L,NE]
I'm wanting to have an url like this /search/#ff2266/, to accept hex (with the #) colors in the url and then have this value in the $_GET['search'] variable. But not only this, but I'm having problem with the #.
Is there any way i could do something like this: ([#0-9a-zA-Z-\s-:]+) ?
I've tried the rule:
RewriteRule ^search/(.*)(/?)$ search.php?search=$1 [NC,L,NE]
And then in the search.php the following code:
echo "var_dump($_GET): ";
var_dump($_GET);
and with the url /search/#f44336/ the result is:
var_dump(Array): array(0) { }
See, the part of a URI after the # is called "fragment" and is by definition only available/processed on client side (see https://en.wikipedia.org/wiki/Fragment_identifier).
On the client side, this can be accessed using javaScript with window.location.hash.
If you want to access that number in your search file, you could pass it to there without the hash char and use it that way.
I'm trying to pass a detail as a get variable using the Wordpress Rewrite Rule API. I'm not great with regex and it's driving me mad. I have tried every combination of the below and I'm not getting anywhere:
function dcc_rewrite_tags() {
add_rewrite_tag('%propref%', '([^&]+)');
}
add_action('init', 'dcc_rewrite_tags', 10, 0);
function dcc_rewrite_rules() {
add_rewrite_rule('^/[^/]*/([^/]*)/?', 'index.php?p=2&propref=$matches[1]', 'top');
}
add_action('init', 'dcc_rewrite_rules', 10, 0);
The url structure is mysite.com/page/get-variable/. I'm just trying to pass the last bit between the slashes as the get variable "propref". Most variations I've tried, it says it can't find the page or drops the last section of slashes.
I need to add a route for the following syntax:
http://www.testsite.com/select?term=query1
In my routes file, I tried using the following
GET /select/{term}
However, the above does not catch the URL - instead it goes to another handler in the config (placed beneath the handler for select/{term}:
GET /{auth}
Any thoughts on fixing or troubleshooting this would be most welcome. thanks
?term= means that term is a parameter - not part of the route you are trying to match
so you'd write
GET /select YourControllerClass.yourMethod
....
YourControllerClass extends Controller {
public static void yourMethod(String term){
Logger.debug("term=" + term);
}
}
If your URL was http://www.testsite.com/select/query1 then the route definition you provided above should work
I am trying to route a URL using codeigniter URL routing.
I want to redirect a url like
/users/edit?email to userController/editemail
/users/edit?password to userController/editpassword
I tried using the following line in routes.php in config folder
$route["users/edit?(email|password)"] = "userController/edit$1";
This displays page not found. I am guessing that ? is being treated as a regular expression character. I tried escaping it but that didn't work either.
I don't want to set the config setting uri_protocol to PATH_INFO or QUERY_STRING, since this is just a pretty URL I want to setup, not pass anything to the action.
Can somebody help me out over here?
Regards
You should escape the ? like this, it should work. (not tested)
$route["users/edit\?(email|password)"] = "userController/edit$1";
Later edit:
This works as intended:
$route["users/edit(email|password)?"] = "userController/edit$1";
The userController looks like this
<?php
class UserController extends Controller {
function edit()
{
echo "general edit";
}
function editemail()
{
echo "edit email!";
}
function editpassword()
{
echo "edit password";
}
}
Router works like this:
if you go to http://sitename/index.php/users/editemail you see editemail() action.
if you go to http://sitename/index.php/users/editpassword you see editpassword() action.
if you go to http://sitename/index.php/users/edit you see the edit() action (the question mark makes optional the email/password field and you can do some other things in edit() action