Hide segment in URL but give code access to hidden segment - php

I'm using Structure and have a "Supernav" page with multiple children that will make up the supernav for the site. I thought this would be a nice way to have all pages on the site accessible to the client via one location: the Structure UI.
If you visit any of the child pages in the "supernav" group the URL comes out like this:
http://website.com/supernav/prospective-students
I'd love to be able to remove the supernav segment of those URLs so that it ends up being:
http://website.com/prospective-students
I don't even want the supernav segment to appear in the status bar when you hover over these links on the page. Is this possible? With CodeIgniter this comes down to a simple routing rule, but I don't know if that's an option with EE.
Appreciate any help I can get!

This may be a bit after the fact, but have you considered using NavEE for this sort of situation and replacing Structure wholesale? You can build multiple navigation content, and don't have to "hide" the content. I love Structure, but you would have to use .htaccess in order to get the results you're wanting, as well as some routing stash/embeds.

You could use Freebie for this as well.
Take control of your URLs — define segments that you want EE to ignore
completely. Use 'freebie' segments to trigger template behavior, build
dynamic archives inside Structure, or just build special URLs for
analytics purposes. Freebie allows you to use segments in powerful,
flexible ways without the hassle of dealing with strict URL parsing
(like Structure's).
You just add supernav to the Freebie settings (under Freebie segments) and supernav can then be ignored. If you still need to run a conditional off of supernav, {segment_1}, you can use {freebie_1} instead. Read more about that in the add-ons documentation over at Devot:ee and in this post by it's creator.
With that said, I'm not positive if you can output the nav using normal Structure tags and get it to display all children of supernav without supernav itself still being in the URL. To get around this you would need to hard code your navigation (or use NavEE or Taxonomy.)
I hope someone can verify if Structure has a tag/param, or not, which addresses this issue as I'm not really sure either way.

Related

How to structure hyperlinks when using Clean URL or Pretty URL

I've tried to search for the best way to handle links on a dynamic website when using "Clean" or "Pretty" URLs, but have not been able to find anything.
I've found a LOT of information on how to use mod_rewrite and try_files, which I've implemented successfully, now my php front controller parses all the parameters on a URL, and it links to the page correctly. No problem here.
The issue I'm having is how to best build all the links on my pages. Currently my links are all in the format eg. "www.site.com?do=post&id=23" which works fine. However I'd like them to display as "www.site.com/post/23" which already also works fine, because of try_files, and how my front controller parses all the parameters from the URL.
However do I now go through all my code and change all the dynamically built links to build in the "www.site.com/post/23" format? It seems like a lot of work, and to be honest I'd like to leave it an "option" to either use Clean or Dirty URLs, similar to how Wordpress allows it as an option in their Admin panel.
Do sites like that keep links in the format "www.site.com?do=post&id=23" and use a rewrite function on all the links when the page is created? So the links show up as Clean when the user sees it?
I'm confused as the best way to handle this, and hope I explained what I'm looking for. I just want to know how best to handle the dynamic links and have it optional to display as clean or dirty url format, for lack of a better word.
Thanks for any help.
That's a very conceitual question...
You could see how Laravel framework router works.
You do not need to use it, but you can get ideas there.
The router class is responsible of know how to create a url to some resource, page, action, whatever you want.
So in your view you just call a method that return the url.

Drupal URL structure for scraping

I am trying to scrape a drupal site with a Python script for music gigs in the past.
In doing this with a wordpress site I would iterate through urls like this:
http://wordpressevents.com/?p=1
...
http://wordpressevents.com/?p=10000
...and that would get me forwarded to a page (if there's one there) that I could scrape. The actual URL would be something like:
http://wordpressevents.com/music/some-band-youve-never-heard-of/
My Drupal site also has sections (e.g. /gigs/ or /classical/ etc).
Is there any way I can find out what their urls might be so that I can go about scraping it with Python and BeautifulSoup (other suggestions welcome)?
Ideally, I would find out what the structure is...
http://drupalevents.com/drupost?=1
...
http://drupalevents.com/drupost?=10000
etc.
But maybe it doesn't work like this?
In drupal the only guaranteed content url structure is /node/[some number]
So the best way to do this to an arbitrary drupal site is to start at /node/1 and go up from there, incrementing by 1 every time. Or if you look at the source of the newest page on the site and find the node id of the page in the body class tag, then you would know the last number and work your way backwards. For example given the node/185324 the body could have the class node-1853524 on it. This might not be there as the body classes could be anything based on how the site was setup.
Most sites also use the pathauto module to give the pages something a bit more friendly than node/123
The pathauto module uses tokens based on things that the site builder specifies to give nice urls to content. One common one is /content/[node:title]. I doubt that this will really help you but at least it will give you some information on how the drupal site is setup.

Masking subdirectories and pages for my website

I want to mask some of the subdirectories and pages for my website. For example:
I want to change
www.example.com/blog.php?post=post1
to
www.example.com/blog
or something similar to that. I have seen examples about redirecting and such but that doesn't seem to work for what I want and I would like to stay away from iframes if possible. I just want the address bar to not reflect my internal directory structure and page names. I want it to keep showing /blog while they are moving from post to post. Thanks.
P.S. I am not using wordpress or any other CMS or blogging system.
You can use apache mod_rewrite for that.
Mod Rewrite Generator
And if You don't want to have the same url on blog-post/article change, but to display different content, all I can think of this moment is by using either POST method or browser cookies, but, that would require a lot of page reloads, and it simply is not recommended for wide use. If You are building per_se (one person only) panel or similar, than url doesn't matter that much, but, speaking of blog..
It is quite reasonable to hide .php extension or url query index/key, but not what You would like to accomplish.
Like I said, it is possible, but Luke .. don't do that.
Blog should be bookmarkable on each and every #stop, and that happens just because of unique urls and hash values. Without these two, no hyperlinking possible *(not to mention seo penals and flaws + dozen of other unwanted obstacles, page caching for instance).

The best PHP search engine-friendly method

What method can you recommended for creating search engine-friendly URLs? When coding in PHP that is. Ideally I would like something like:
http://www.example.com/article/523544
So it doesn't display the file it's opening (eg article.php)
It is quite necessary to generate a SEO friendly URL's so that most of the Search engines can easily index it.And the most interesting part with it that URL can easily correlate to the Page Content and the User can generate a Pretty URL as per the keywords he want to rank the page on different Search Engines(e.g. google.com,google.co.in,bing.com)
The best example to have Pretty Links is on Wordpress.It actually stores the Dynamic Page URL's in the Database itself.And when the Pretty Ur is being called,internally the htaccess is called and it redirects to the original dynamic page in the system.
Some basic tips from
Google
SEOmoz
may help you.
Some topics in SO:
mod_rewrite
nice url
Edit:
You need to place a .htaccess file in your document root that includes the following rules:
RewriteEngine on
RewriteRule ^article/([0-9]+)?$ article.php?id=$1 [L]
Make sure mod_rewrite enabled in Apache and you are allowed to use it.
If you read some questions in SO in this topic it will help you understand how mod_rewrite works.
To make your urls more search engine friendly you may want to use 'slugs' so you need to sanitize your article titles like in this url.
Ideally your URL needs to contain something about the topic of the URL. You gave the example of http://www.example.com/article/523544, where this is better than using standard query strings, it's still not ideal, as all that any search engine can see from it is that it's an article.
It's important to remember that the segment (a segment is the string between each slash) closest to the domain is the most important:
http://www.example.com/most-important/next-important/less-important/
I personally always try to use the following URL structure, and keep my page/article titles unique:
http://www.example.com/this-wonderful-article
Notice the use of dashes and not underscores, this is generally known as the preferred method. Using this method I usually generate and save the article's slug ('this-wonderful-article') in the database, and then search for that instead of an ID.
Appreciated that sometimes it's very difficult to just use slug, especially with a larger website. You may have multiple articles with the same title, or the website may have user-submitted content over which you have no control. If this is the case, you can use the ID without any worries, but just be sure to include the title of the article in the URL. Eg: http://www.example.com/this-wonderful-article/29587
If you're looking for a method of using these URLs then I'd suggest looking at some mod_rewrite tutorials. Personally I use a framework that does the majority of the legwork for me such as CodeIgniter (http://www.codeigniter.com), or you could use something like the Zend Framework or CakePHP. If you're only doing articles then it might be worth looking into a sturdy CMS like WordPress, although this depends largely on your requirements.

REALLY basic mod_rewrite question

I am trying to use SEO-friendly URLs for a website. The website displays information in hierarchical manner. For instance, if my website was about cars I would want the URL 'http://example.com/ford' to show all Ford models stored in my 'cars' table. Then the URL 'http://example.com/ford/explorer' would show all the Ford Explorer Models (V-6, V-8, Premium, etc).
Now for the question:
Is mod_rewrite used to rewrite a query string style URL into a semantic URL, or the other way around? In other words, when I use JavaScript to set window.location=$URL, should the URL be the query string version 'http://example.com/page.php?type=ford&model=explorer' OR do I internally use 'http://example.com/ford/explorer' which then gives me access to the query string variables?
Hopefully, someone can see my confusion with this issue. For what it's worth, I do have unique 'slugs' made for all my top level categories (obviously, the site isn't about cars).
Thanks for all the help so far. I got the rewrite working but it is affecting other paths on the site (CSS, JavaScript, images). I using the correct path structure for all these includes (ie '/images/car.png' and '/css/main.css'). Do I have to use an absolute path ('http://example.com/css/main.css') for all files? Thanks!
Generally, people who use mod_rewrite use the terminology like this:
I want mod_rewrite to rewrite A to be B.
What this means is that any request from the outside world for page A gets rewritten to file B on the server.
You want the outside world to see URLs that look like
A) http://example.com/ford/explorer
but your web server wants them to look like
B) http://example.com/page.php?type=ford&model=explorer
I would say you want to rewrite (A) to look like (B), or you want to rewrite the semantic URL into a query string URL.
Since all the links on your page are clicked on by the user and/or requested by the browser, you want them to look like (A). This includes links that javascript uses in window.location. They can and should look like (A).
once you have set up mod_rewrite then your links should point to the mod_rewritten version of the URL (in your example: http://mysite.com/ford/explorer). Internally in your system you will still reference the variables as if they are traditional query string name value pairs though.
Its also worth pointing out that Google is now starting to advocate more logical URLs from a search engine point of view, i.e. a query string over mod rewrite
Does that mean I should avoid
rewriting dynamic URLs at all? That's
our recommendation, unless your
rewrites are limited to removing
unnecessary parameters, or you are
very diligent in removing all
parameters that could cause problems.
If you transform your dynamic URL to
make it look static you should be
aware that we might not be able to
interpret the information correctly in
all cases
http://googlewebmastercentral.blogspot.com/2008/09/dynamic-urls-vs-static-urls.html
also worth looking at:
http://googlewebmastercentral.blogspot.com/2009/08/optimize-your-crawling-indexing.html

Categories