Significance of a using colon in Joomla URL - joomla

I need to know, if joomla gives any significance to a colon in within component or view?
Is there something in this naming convention?

The colon is only used in the 'id' parameter to separate the numeric id from the slug used for SEF URLs. With view & component names you should not use any colons.
Eg:
Non-sef URL - /index.php?option=com_content&view=article&id=45:my-article-title
Sef URL - /my-article-title.html
Also when actually using the id, you should only use the numeric part, which can be extracted using JRequest::getInt('id') in your code.

Related

Is there a DNN URL decode method as it is changing a URL Encode

We are using Server.URLEncode to change an SKU with a forward slash from BDF5555/45 to BD5555%2F45 in our Href on a button.
When a person clicks on the button the page navigates to another module which has Request.QueryString but DNN is changing the URL.
How can I get the variable decodeprodCode to include the &45 as BDF5555/45?
Perhaps DNN is rewriting the URL?
There is a NavigateURL class in DotNetNuke.Common.Globals that will generate a correct url based on a TabID and a lot of overloads.
DotNetNuke.Common.Globals.NavigateURL(TabId)
You can also use querystring parameters
DotNetNuke.Common.Globals.NavigateURL(TabId, ControlKey,"key=value"))
DNN by default will re-write querystring values into /key/value format in the URL assuming that it is properly encoded. For example if you have querystring values of sku=1 and productid = 2 the resultant URL will be
https://yoursite.com/Your-Page/sku/1/productid/2
This is done via the FriendlyUrlProvider, but it should not have any impact to your ability to process via Request.Querystring as this is a very, very common practice for passing values into DNN.
Your code to retrieve the value is correct.
I ended up using the following code instead of a Request.Querystring.
string RawurlFromRequest = Request.RawUrl;
var cleanSKU = RawurlFromRequest.Split(new[] {"sku/"}, StringSplitOptions.None)[1];
var CleanSKUNoOtherQueryStrings = cleanSKU.Split(new[] {"&"}, StringSplitOptions.None)[0];
The Request.RawURL brings back the URL with the special characters as it is without encoding. As Mitchel Sellers mentioned above, DNN uses the FriendlyURLProvider which rewrites the URL.
For example www.mysite.com/ProductFilter/SKU/BDF5555/45 and not
www.mysite.com/ProductFilter/SKU/BDF5555%2F45
The CleanSKU variable will look for SKU/ and split everything on the left as it is set to [1].
After everything has been split on the left, we look for other QueryStrings which we usually add with a & sign. We will split everything on the right by setting it to [0].
This will bring back BDF5555/45 in the backend with a forward slash which we can use to retrieve product information from our ERP system which URLdecode couldn't do.

Shorten URLs within CodeIgniter

This question has been asked a few times but I can't seem to find a solution that helps me which is why I am trying here.
I have my site setup with the following for URLs I am using CodeIgniter I have a controller called user which loads a user view.
So my URLs are structured as follows:
http://example.com/user/#/username
I want to try and strip out the user controller from the URL to tidy up my URL so they would just read:
http://example.com/#/username
Is this possible I have been looking at route and have tried lots of different options but none have worked?
$route['/'] = "user";
Could anyone offer any solution?
Assuming the '#' in your URLs is a valid function and 'username' is a parameter for that function, then this route should work:
$route['#/(:any)'] = "user/#/$1";
Depending on what usernames are to be routed you may want to change the wildcard. For example, if you only wanted to route numbers as the parameter, you could change (:any) to (:num).
(:num) will match a segment containing only numbers.
(:any) will match a segment containing any character.
You can also use regular expressions to define routing rules, allowing you to further restrict what is routed.

Codeigniter URL routing solution for my website

I have a website that is developed with CodeIgniter. I have added the route for my url as follows:
$route['about_us'] = 'about-us';
Now I have a problem with that. I.e. when I am looking for the url www.mysite.com/about_us it works and at same time www.mysite.com/about-us is also working. I want only one url to work: the one with the underscore.
I have removed this to:
$route['about_us'] = 'about-us';
But the url www.mysite.com/about-us still works. It may cause duplicate content for my website in Google and so more page links also showing. Even I don't have that functions too. Like www.mysite.com/about_us/design. Likewise in about_us controller file index function only there, but design method calling in Google.
How do I resolve this problem?
You actually don't need a route here. The normal purpose of request routing the way you are using it is so that you can use hyphenated URLs when hyphens are not permitted in class and function names. I.E. you want the url to by www.example.com/test-controller, but you can't actually name a controller test-controller because the hyphen is illegal.
If you only want to have the underscored URL such as www.mysite.com/about_us then just remove the route completely and name the controller about_us. With no routing rules the hyphenated url should 404.

CodeIgniter - Properly formatted URLs

I'm having some problems learning how to program proper URLs in codeigniter ... im finding that controller names cant have hyphens, only underscores.
Ill tell you the process in doing, and if someone could let me know where im going wrong, that would be great.
Ok, im my view I have a button that links to a page, for example about_us.
About Us
This then loads the about_us.php controller, inside the controller i have
$this->load->view('about_us');
That then loads about_us.php in the view and shows the page.
I have found that it doesnt have a problem with underscores, but I want to use hyphens for URLs instead of underscores.
When I try and call a controller about-us.php it doesnt work, when I rename the class header class About-us extends Controller { it doesnt work :S
I'm really confused how to get good looking URLs.
Any advice would be grand.
Cheers
A PHP class cannot have a hyphen in its name. That's why naming your class About-us didn't work.
If you're set on having hyphens in your URLs, you should look at CodeIgniter's custom URI routing.
http://ellislab.com/codeigniter/user_guide/general/routing.html
See the section on regular expressions down near the bottom of the page. You can set up a regular expression to replace the hyphens in your URLs to underscores - that way, your users will see the hyphens, but CodeIgniter will use the underscores.

How to find the non-SEF URL whilst SEF is enabled (Joomla 1.5)?

I know you probably don't get many questions like this...
I am working on a component that I want to be able to deal with the non-SEF URLs whilst SEF is enabled, whether it be the built-in SEF or something like sh404sef.
Does Joomla store the ORIGINAL non-SEF URL anywhere ie. index.php?com=com_fred&view=homepage?
I've found that any SEF activated, changes the JURI::getInstance() value to the SEF equivilant.
I've also found the the $REQUEST['URI'] value does not work on all platforms/servers etc.
Thanks for any help
Get all vars from the GET/POST request into an array. At this point you may also modify the values before generating the URL string.
$getVars = JRequest::get( 'GET' );
If you really need the URL string, you can obtained with:
$newURL = http_build_query($getVars);
Hope it helps!
I came back to this code and tried again but gave me some errors, so I've reworked it partially based on the previous answer I've formulated before with this new one (working nice on Joomla! 3.4.5)
// build the JInput object
$jinput = JFactory::getApplication()->input;
// retrieve the array of values from the request (stored in the application environment) to form the query
$uriQuery = $jinput->getArray();
// build the the query as a string
echo 'index.php?' . JUri::buildQuery($uriQuery);
Joomla! API Docs: JInput - JUri
PREVIOUS ANSWER:
Googling around I found this:
<?php
// "unparse" the Joomla SEF url to get the internal joomla URL
JURI::current();// It's very strange, but without this line at least Joomla 3 fails to fulfill the task
$router =& JSite::getRouter();// get router
$query = $router->parse(JURI::getInstance()); // Get the real joomla query as an array - parse current joomla link
$url = 'index.php?'.JURI::getInstance()->buildQuery($query);
?>
I've tested it with Joomla! 3.4.4 and its working fine! Dunno if it can work with 1.5
You can use JRequest::get(true) to get an array of all the query parameters from the URL. A quick note though, I haven't checked it enough to know if it only returns GET parameters or it does all REQUEST parameters (which I think is more likely). It might, however, help with what you're looking for.
For menu items, it's stored in the 'jos_menu' table, in the 'link' column (but the itemid is not in this string - it's the 'id' column).
For anything else, it's probably not stored in the database, but can normally be worked out pretty easily, especially with core components. It can be a little bit of a pain with third party components, but you can look through the MVC architecture of most components to figure it out.
Otherwise, you could always turn off SEF on your dev site/create a dev site for this.
Is there a specific component that you're curious about?
The link that I posted here:
Joomla URLs: An article doesn't have a pretty URL by itself?
provides a very good "crash course" for URLs in Joomla 1.5
You don't have to do anything special for non-SEF URLs. Even if you have SEF URLs turned on, Joomla will still display the correct page if someone access the site with a non-SEF URL. The portion of your component that handles SEF URLs, the router, only tells Joomla how to use the URL information to determine what to display. When presented with a non-SEF URL Joomla just parses the query string as it normally would.
For any given component, the URL is built like this -
index.php?option=com_name&view=XXXX&id=1111&Itemid=11111
option is the name of the component
view is of course which view to display
id is the id of the particular content item
itemid is the menu item it used to determine module/template assignment

Resources