Twitter/Facebook Like URLs ( Pages, UserNames and About Page ) htaccess - apache

Okay, Here are three Facebook URLs:
http://facebook.com/about [A Facebook Page]
http://facebook.com/zuck [Zuckerberg's Profile]
http://facebook.com/like [About Facebook Like Button]
If I have two pages:
http://example.com/user.php?u=[username]
http://example.com/page.php?p=[pagename]
I have successfully rewritten the user.php as http://example.com/[username] but after that when I use the same code for page, and try to access a page like http://example.com/[pagename], a userpage (404 page, because no user with that name exists but a page does) appears. So, What should I do to remove this conflict.
NOTE: I don't want to use URLs like http://example.com/user/Username and http://example.com/page/PageName. Please Help.

You need to rewrite all urls to a separate php file that detects whether the parameter is a username, or page name. The php should look something like this:
$name = $_GET['name']
if( userNameExists($name) )
include('user.php');
else if ( pageNameExists($name) )
include('page.php');
else
include('404page.php');
You need to implement userNameExists() and pageNameExists() off course.

Related

How to store URL in table and use as link on table?

I want to implement bookmark. I have problem with saving correct URL, when I store complete URL this link work till session is same as current.
I can store URL as:
'f?p=':APP_ID||':'||:APP_PAGE_ID
but what to store as a session? Pages are not public.
Don't reinvent the wheel - use APEX_PAGE.GET_URL instead. For example:
select APEX_PAGE.GET_URL (p_page => :APP_PAGE) as URL
from dual;
The result is then something like this:
f?p=12488:3:109743317382702:::::
Live screenshot from apex.oracle.com:

How to make seo url for Yii $_GET method using url manager?

I'm working on a site on local server. I have made a form to search country,state and city. After getting the results I see the URL formatted as URL
I want to make this URL as URL
So here I want to know about URL manager rules so I can make it as I want.
Simply add this rule in your url-manager
"site/searchme/<country>/<state>/<city>" => "site/searchme"
Now, you need to have an action with this signature:
public function actionSearchme($country, $state, $city)
You can access $country, $state, $city from url inside this action. For example if your url be like http://localhost/yii_1/site/searchme/UnitedStates/Washington/NewYork, $country will equal "UnitedStates" and so on.

How to add additional variables in yii url

I'm working with Yii framework and i'm trying to implement "create pdf" button on all sorts of different url's.
My first plan was to simply add variable to url where "create pdf" button links:
'url' => Yii::app()->request->getUrl().'&pdf=true',
And it works fine on all links except when i enter directly to site like: www.example.com. In that case there is no index.php in url so button link is unusable as it looks like this:
www.example.com/&pdf=true
Is there Yii way to append variables to url or I need to do manual checks?
create your links like this :
Yii::app()->createUrl('controllerName/actionName', array('number' => 2, 'name'=>'john'));
//or this if you want it with http:://
Yii::app()->createAbsoluteUrl('controllerName/actionName', array('number' => 2, 'name'=>'john'));
you can add your parameter(s) to the original parameters with the CMap::mergeArray($_GET, array('pdf' => 'true'))
and use the Yii::app()->createUrl or your Controller's createUrl function:
http://www.yiiframework.com/doc/api/1.1/CApplication#createUrl-detail
http://www.yiiframework.com/doc/api/1.1/CController#createUrl-detail

How to Detect and Redirect from URL with Anchor Using mod_rewrite/htaccess?

I've seen a number of examples of the opposite, but I'm looking to go from an anchor/hash URL to a non-anchor URL, like so:
From: http://old.swfaddress-site.com/#/page/name
To: http://new.html-site.com/page/name
None of the examples at http://karoshiethos.com/2008/07/25/handling-urlencoded-swfaddress-links-with-mod_rewrite/ have functioned for me. It sounds like REQUEST_URI has the /#/stuff in it, but neither me nor my Apache (2.0.54) see it.
Any ideas, past experiences or successes?
Anything after the # is a fragment, and will not be sent to the webserver. You cannot capture it at any point there, you'll have to use a client-sided approach to capture those.
#RobRuchte : would it not be better to use window.location.hash, with a replace instead of a regular expression?
var redirectFragment = window.location.hash.replace(/^#/,'');
if ( '' !== redirectFragment ) {
window.location = 'http://new.html-site.com' + redirectFragment;
}
I'm the author of the post you linked to. Wrikken is correct, the content after the named anchor is not sent to the server unless something has mangled the URL along the way. On the client side, you need some JavaScript like this in your landing page to redirect the swfaddress links to corresponding URLs on another domain:
var re = new RegExp('#(.*)');
var redirectFragment = re.exec(document.location.toString());
if (redirectFragment!=null)
{
document.location = 'http://new.html-site.com'+redirectFragment[1];
}
I used a modified version of the answer by #m14t. This works for redirects that look like http://example.com/path/to/page#fragment --> http://example.com/path/to/page/fragment. Notice that I also concatenated the window.location.pathname for the redirect, otherwise I would not get the full path for the redirect. If the new file path is completely different from the old one, then this would not work.
var redirectFragment = window.location.hash.replace(/#/,'/');
if ( '' !== redirectFragment ) {
window.location = 'http://example.com' + window.location.pathname + redirectFragment;
}
In my case, I needed to build fragmented links into individual pages, which is part of what is commonly done to improve a website's SEO.

Apache friendly urls

I've got a small CMS system written in PHP and running on Apache. The format of the URLs this CMS system uses/generates is:
/display.php?PageID=xxx where xxx is just some integer number. As you can see, those URLs are not very friendly, neither for users nor search engines.
I believe that using mod_rewrite (or something like that) and .htaccess files I should be able to configure Apache for URL-rewriting. I have searched for information about this before but I did not find any easy method to do this, it always involved messing with regular expressions, which I'm not very familiar with.
Since the website in question is really simple and small, just 5-10 different pages, I would really like to be able to just hard-code the configuration, without any special rules or regexps.
I'd just like to map a friendly URL to an actual URL, perhaps like this:
/about = /display.php?PageID=44
/products = /display.php?PageID=34
etc.
Is it possible to configure the mod_rewrite plugin in a basic way like this?
Could someone explain the easiest method to do this? Explain it to me as if I was a child :-)
Thanks in advance!
well putting something like
RewriteEngine on
RewriteRule ^about$ ./display.php?PageID=44
RewriteRule ^products$ ./display.php?PageID=34
in your .htaccess-file shouldn't be the big deal I think...
URL Rewriting for Beginners is my favorite intro article to this, it should cover what you're looking for. In fact, the first actual example where you write a .htaccess file is almost identical to what you want.
Another way is filter by a dynamic php file with a mapping for pages or a routing strategy like frameworks like drupal code igniter ....
and your URL will be like
my-pages/about.html -> display.php?PageID=44
my-pages/products.html -> display.php?PageID=34
and so on
Here a suggestion for .htaccess file and the filter the action with this strategy
--- .htaccess file ----
*RewriteEngine on
RewriteRule ^my-pages/(.).html$ MY-URL.php [QSA,L,E]
---------------- MY-URL.php ---------
<?php
$PREFIX = 'my-pages/'; //--- not used
$mapping=array(
'about' => 44,
'products' => 34
);
$pathinfo= pathinfo( $_SERVER['REQUEST_URI'] );
/* $pathinfo['dirname'] -> my-pages
$pathinfo['basename'] -> ???.html
$pathinfo['extension']-> .html
*/
$page = substr( $pathinfo['basename'] ,0,-5);
if( isset( $mapping[$page] ){
// ---- redirect or include
YUOR CODE HERE
}
else {
//--- error 404
YUOR CODE HERE
}
?>