I want to redirect a link from
www.example.com/ex.php?name=andy
to
www.andy.example.com
Can you give me the code please
Why use .htaccess? You can do that with PHP.
<?php
$url = 'http://www.'. $_GET['name'] .'.example.com';
header('Location: '. $url);
?>
Just make sure you don't output any text before using header().
To get the name from the subdomain URL do the following.
<?php
$new_url = $_SERVER["SERVER_NAME"];
$url_parts = explode('.', $new_url);
echo 'Name is: '. $url_parts[0];
?>
james.example.com results in "Name is: james".
Related
<?php
include '../protocol/httpsocket.php';
$sock = new HTTPSocket;
$sock->connect('localhost',2222);
$sock->set_login('admin','admin_password');
$show_user='user5';
$sock->query('/CMD_API_SHOW_USER_CONFIG?user='.$show_user);
$result = $sock->fetch_parsed_body();
print_r($result);
?>
This above code return:
white page with only "Array ( )"
Connection with DA is correct, because I can create user API etc.
Try add $sock->set_method('POST'); or $sock->set_method('GET'); after $sock->set_login('admin','admin_password');
How can I rewrite a rule for the url
navi.php?a=815&lang=eng
and a meta title
How can I post a Video
into
/en/How-can-I-post-a-Video
Can the Meta Title be fetched somehow to add it to url?
Instead of passing the params in the url, you need to form a url with meta tag title. From the url take the arguements and match with the database and get the result data. This is how the .htaccess will work.
You can make a rewrite rule like so:
RewriteRule ^(.*)$ index.php?params=$1 [NC]
This will make your actual php file like so:
index.php?params=value¶m=value
And your actual URL would be like so:
http://url.com/params/param/value/param/value
And in your PHP file you could access your params by exploding this like so:
<?php
$params = explode( "/", $_GET['params'] );
for($i = 0; $i < count($params); $i+=2) {
echo $params[$i] ." has value: ". $params[$i+1] ."<br />";
}
?>
zero.php
<?php
$q = $_GET['id'];
echo = $q
?>
this code is not working, Help me!
I am not using .htaccess in this.
Try this.
<?php
$q = $_GET['value'];
echo $q;
Your syntax is significantly off.
Have you tried?
<?php
$q = $_GET['id'];
echo $q;
?>
and of course this is assuming that there is a GET parameter called id it is being passed so a even better solution would be to check to see if it is defined first.
<?php
if (isset($_GET['id'])) {
$q = $_GET['id'];
echo $q;
} else {
echo "ID PARAMETER NOT SET";
}
?>
I have a page template where I run a WP_Query
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('post_type=post&posts_per_page=4'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
The issue I'm facing is that if you go to the site /page/100 it will show the template and it's not going to a 404 when It should.
My blog page under reading settings is another page and this is a custom template I'm doing.
I have read this post https://wordpress.stackexchange.com/questions/46116/non-existing-blog-pages-are-not-redirected-to-404 and tried all the functions and none of them work.
I also spent 3 hours searching on google without being able to find a workaround.
You are creating a new WP Query. So I think you have to reset the wp_postdata.
WP Codex offers sample code. You could try something like
$wp_query = new WP_Query();
$wp_query->query('post_type=post&posts_per_page=4'.'&paged='.$paged);
if( ($wp_query->have_posts() ) :
while ($wp_query->have_posts()) : $wp_query->the_post();
// Do here something with the post
endwhile;
wp_reset_postdata(); // At the end reset your query
endif;
While using WP_Query for displaying posts list you need to check by yourself if they are any posts for current page. Below is example code from Wordpress docs
<?php if ( have_posts() ) : ?>
<!-- Add the pagination functions here. -->
<!-- Start of the main loop. -->
<?php while ( have_posts() ) : the_post(); ?>
<!-- the rest of your theme's main loop -->
<?php endwhile; ?>
<!-- End of the main loop -->
<!-- Add the pagination functions here. -->
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
Replace " _e('Sorry, no posts matched your criteria.'); "
with own error or function displaying 404 error.
Edit: Above code is of course example for Main Loop. In your particular case you need to call $wp_query->have_posts() and make sure it not evaluates to false. If it does display 404 error.
for example:
if(!$wp_query->have_posts()) {
echo "404";
}
Or if you want server respond with HTTP code 404 instead of 200 then you should try something like this:
if(!$wp_query->have_posts()) {
status_header(404);
nocache_headers();
include( get_404_template() );
exit;
}
I am trying to echo a request in the view file in Kohana using Request::factory() method and i am sending a value in that request which i am unable to get in the User Controller here is my code:
The View file:
<h1> Welcome to My First View File </h1>
<?php echo Request::factory("user",array("id" => 123))->execute(); ?>
Then the User.php Controller have this code:
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_User extends Controller {
public function action_index()
{
$value = $this->request->param('id');
$content = View::factory('menu')->bind("id", $value);
$this->response->body($content);
}
} // End User
and the view menu.php have this code:
<h2> This is the view called by Request and Parameters send was:
<?php echo $id; ?>
</h2>
when i run the code it display the text This is the view called by Request and Parameters send was: but it doesn't display the $id anyone can tell me why?
P.S: sorry for my bad English as its not my native language
Here you can see, that Request::factory() requires URI value a the first param. So, you should call something like:
<h1> Welcome to My First View File </h1>
<?php echo Request::factory(Route::get("user")->uri(array("id" => 123)))->execute(); ?>
or
<h1> Welcome to My First View File </h1>
<?php echo Request::factory("user/123")->execute(); ?>
First example uses reverse routing, where "user" is a Route name. I assume that you already have Route for handling URIs like '/user/123'.