HTACCESS: can I set one /mobile URL to one page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

HTACCESS: can I set one /mobile URL to one page?

Post by simonmlewis »

I need to point a particular shorturl to a particular page.

Most pages like domain.com/newproducts, go to index.php?page=<title>
But I want to do a specific one:
domain.com/mobile, to go to index_ip.php?page=ihome.

I thought this would work, but it doesn't:

Code: Select all

RewriteRule ^([^/\.]+)/?$ index.php?page=$1&menu=home [L]
RewriteRule ^mobile/ index_ip.php?page=ihome [L]
Doesn't work the other way around either.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: HTACCESS: can I set one /mobile URL to one page?

Post by AbraCadaver »

Without testing it, I would say that the first rule matches and then it terminates never getting to the next rule. Try:
[text]RewriteRule ^mobile/ index_ip.php?page=ihome [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1&menu=home [L][/text]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: HTACCESS: can I set one /mobile URL to one page?

Post by AbraCadaver »

And maybe the / is not in the URL at that position? You might try:
[text]RewriteRule ^/mobile
or
RewriteRule ^mobile[/text]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS: can I set one /mobile URL to one page?

Post by simonmlewis »

Doesn't work.
This script rejects it as an unknown page and takes me to my error page:

Code: Select all

  function getPage()
  {
  $thispage="includes/".$_GET['page'].".inc";

  if (file_exists($thispage)) 
  {
   include $thispage;
  } 
  else 
  {
  echo "<meta http-equiv='Refresh' content='0 ;URL=/error'>";
  }
  } 
HTACCESS needs to see it as a page.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS: can I set one /mobile URL to one page?

Post by simonmlewis »

Code: Select all

RewriteRule ^/mobile index_ip.php?page=ihome [L]
RewriteRule ^/mobile/ index_ip.php?page=ihome [L]
Neither of these work.
They both just go to my error page.
Also, I do have this right at the top of the HTACCESS.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: HTACCESS: can I set one /mobile URL to one page?

Post by requinix »

.htaccess and mod_rewrite don't "see" anything as "pages". All they do is change the URL.

If your index_ip.php does not accept page=ihome then you have to fix it so it does. Is the page it should be executing named includes/ihome.inc?
Post Reply