mod-rewrite in the eZ Publish Framework - mod-rewrite

I'm currently using the eZ Framework as part of my new job.
mod-rewrites are handled in 2 sections of the GUI admin interface:
1 - URL translator
2 - URL wildcard
The URL translator essentially handles single rewrites
The URL wildcard is... as the name suggests meant to be wildcard, so can handle *
At the moment, when a new competition is created a new "URL translator" needs to be added. This gets ugly when there are 25 competitions and 15 are old and out of date.
This is what the data entry person has to enter at the moment for a new competition:
URL = /places/competitions/the-name-of-the-comp/process
TO = competition/process
We have tried writing a wildcard catch all, so new comps don't have to be entered as a single rewrite:
URL = /places/*/process
To = competition/process
But, as you may have guessed, it is not working.
If anyone is an eZ Publishing master and knows if this can be done i would be very appreciative.
Thanks,
John

Related

Codeigniter Routes.php within folder

I am using the latest version of CodeIgniter on Server2008 with IIS7.5
I have all of my CI files in a folder mywebsite.com/survey
nps = Controller
survey = Function
client_id = variable base64 encoded client number
I have a script that runs when you visit:
http://mywebsite.com/survey/nps/survey/client_id/MjgzOTcyMW
But I want for it to run when you visit:
http://mywebsite.com/survey/MjgzOTcyMW
How do I set up my routes.php?
I currently have:
$route['/:any'] = 'nps/survey/client_id/';
try
$route['(:any)'] = 'nps/survey/client_id/$1';
or
$route['survey/(:any)'] = 'nps/survey/client_id/$1';
You have to make sure you don't mix up your routes here:
Using just $route['/:any'] would be wrong (even if you had the (:any) correct.
To properly define a route), remember that the left hand side is the pattern route, and the right hand (after the =) is the translated controller/method/parameter format.
So define the route (after all your other routes) as they are to be ordered from MOST specific to least specific (similar to ALLOW/DENY rules etc;):
$route['survey/(:any)'] = 'nps/survey/client_id/$1';

How to Delete a Google Site by its id

I am unable to find out how can I delete a Google Site given its ID. I guess I need to create the SiteEntry for that site and call delete() method, but no idea on how to create the SiteEntry with just the ID.
This is how I am creating the sites:
SitesService client = new SitesService("domain-AppName-v1");
client.setUserCredentials("adminUSer#domain.com", "password");
//Define Site
SiteEntry entry = new SiteEntry();
entry.setTitle(new PlainTextConstruct("Accounting 001"));
entry.setSummary(new PlainTextConstruct("Accounting 001"));
entry.getCategories().add(new Category(TagCategory.Scheme.TAG, "Course Sessions", null));
//Create the site
SiteEntry result = client.insert(new URL("https://sites.google.com/feeds/site/domain.com/"), entry);
//This Delete does not work
result.delete();
//Trying to setup the id in a SiteEntry, it doesn't work either
SiteEntry e = new SiteEntry();
e.setId(result.getId());
e.delete();
This turned out to be a stupid question.
First, https://developers.google.com/google-apps/sites/faq#DeleteSite states the API doesn't support deleting Sites yet, and they must be deleted manually via the web panel. This really sucks because I currently have hundreds of sites created with the API and it is a pain in the ass to delete them manually :-(
Second, siteEntry.delete() throws an Exception saying "delete not implemented", so I was wrong when adding that as working in the question code.
Finally, to retrieve a SiteEntry you must do like this:
SitesService client = <initialize the service>
SiteEntry site = client.getEntry(new URL(siteID), SiteEntry.class);

Different URL keys for different language CMS pages

I'm currently setting up a Magento shop that will support a few different languages.
One issue that I ran into is that I can't find out how to link two CMS pages together, so that when a user switches their language, they are automatically forwarded to the current CMS page but in their preferred language. One option would be to use the same URL key for both pages, but that wouldn't be very user friendly as some users would then see URL keys not in their native language.
Let me give you an example:
I have an "About us" page. In the English version of the store, the URL of that page is /about-us. Now a German user lands on that page and switches his language. But because the German equivalent to "About us" is "Über uns", the German version of that page is at /ueber-uns, so the user would be presented a 404 page because no German version of /about-us exists.
Does anybody know how to solve this issue?
Update: Did some more research and found nothing. I can't believe I am the only one with this problem? The go-to solution, using the same URL key for all languages, seems very ugly and not very user friendly!
So, the only solution that I found was to manually create a redirect for each page in the Magento Rewrite Rules. Do do that, go to Catalog -> URL Rewrite Management and add each page in the following format:
So if a user is using the Francais store view and requests /url-in-english, the redirect will kick in and redirect the user to /url-in-french.
This is of course not an ideal solution, it would be preferred if two pages could be "linked" directly, but I suppose I will have to use this for the moment. If anybody comes up with a better solution feel free to add yours!
I have seen this bug in Magento CE 1.8.0.0. The problem here was a wrong assignment in \app\code\core\Mage\Core\Model\Url\Rewrite\Request.php.
To solve this problem it is sufficient to change the assignment of $fromStore in the protected function _rewriteDb() within the Mage_Core_Model_Url_Rewrite_Request class from
$fromStore = $this->_request->getQuery('___from_store');
to
$fromStore = Mage::getModel('core/store')->load($this->_request->getQuery('___from_store'), 'code')->getId();
with the result that we can access the $stores array with the right key (with the store id instead of the store code). With this the if statement
if (!empty($stores[$fromStore])) {
works in the right way.
As a reminder: Do not modify core files. Just copy \app\code\core\Mage\Core\Model\Url\Rewrite\Request.php to \app\code\local\Mage\Core\Model\Url\Rewrite\Request.php before any change.
You will find this answer in German here: Rewrite von Seiten in verschiedenen Sprachen und verschiedenen URL Keys in Magento
Above solution works but takes a while. We just did the following to rewrite the language changer url when on a cms page to go to the base url:
Add the following code to app/design/frontend/default/template_name/template/page/switch/languages.html after the part where the $url variable is filled (on our it was like
$url = /*explode( '?',*/$_lang->getCurrentUrl()/*);*/;
so we added the following:
if(($this->getRequest()->getModuleName() == 'cms') && strpos($url,'.com/')){$url = strstr($url, '.com/', true) . '.com/';}
elseif(($this->getRequest()->getModuleName() == 'cms') && strpos($url,'.de/')){$url = strstr($url, '.de/', true) . '.de/';}
elseif(($this->getRequest()->getModuleName() == 'cms') && strpos($url,'.nl/')){$url = strstr($url, '.nl/', true) . '.nl/';}
What I did here is check if on a cms page and check if the url contains either .com/ ; .de/ or .nl and strip the part before then add the domain extension back.
in our example: http://www.mega-watch.com/about-us?blabla will become http://www.mega-watch.com/
Hope this helps someone out..

Adding an extension to the blog post pages on liferay

My problem is i want to add '.html' extension to my every blog post. For example right now i have a blog post url 'http://www.indu.com/blog/-/blogs/creating-a-custom-portlet-in-liferay' and what i want is 'http://www.indu.com/blog/-/blogs/creating-a-custom-portlet-in-liferay.html'
I would be grateful if any one can help?
I wonder why would you want this.
Anyways, I think you can change the urlTitle field of BlogsEntry and append .html to the string. May be use a service-wrapper-hook to append .html to the urlTitle whenever a blog is created or updated.
Or you can even use a ModelListener if it exists for BlogsEntry hook to update the blog's urlTitle by using onCreate & onUpdate methods.
Edit
The urlTitle field is present in the BlogsEntry table.
You can access this in java with the following methods:
BlogsEntry blog = BlogsEntryLocalServiceUtil.getBlogsEntry(90989); // retrieves the blog-entry
String blogUrlTitle = blog.getUrlTitle();
blog.setUrlTitle(blogUrlTitle + ".html"); // this would set the string
You can have a check for the blogUrlTitle so that you don't have repeated .html appended to the string:
if (!blogUrlTitle.contains(".html")) { // append only if the title does not contain `.html`
blog.setUrlTitle(blogUrlTitle + ".html");
}
You can refine your code as you like, the above is just a guide-line.
As a side-note, I would always try to reason with the client why they want something, this helps not only to fend-off bad-change-requests but also helps in giving an alternative to the client (which is less taxing on the developers like us ;-) ). In most cases this helps to understand the client's business better & provide better returns.

SEO-friendly URLs in CodeIgniter without the use of slugs?

Is there a way (via routing) in CodeIgniter to change:
example.com/category/4 to example.com/category/foo-bar
where Foo Bar is the name of category 4 in the database?
Access from the SEO-friendly URL should be allowed, but access via the integer should cause a 404 error.
This should also work dynamically, where any integer is automatically converted to a URL-safe version of its corresponding category name.
I've seen a few solutions that use 'slugs'... is there a decent alternative?
Thanks.
I've only been working with CodeIgniter for the past couple of months in my spare time, so I'm still learning, but I'll take a shot at this (be gentle):
There is a url_title() function in the URL Helper (which will need loaded, of course) that will change Foo Bar to foo-bar.
$name = 'Foo Bar';
$seo_name = url_title($name, TRUE);
// Produces: foo-bar
http://codeigniter.com/user_guide/helpers/url_helper.html
The URL helper strips illegal characters and throws in the hyphens by default (underscores, by parameter) and the TRUE parameter will lowercase everything.
To solve your problem, I suppose you could either do a foreach statement in your routes.php file or pass the url_title() value to the URL, rather than the ID, and modify your code to match the url_title() value with its category name in the DB.
Afaik the link between 4 and "foo-bar" has to be stored in the DB, so you'll have to run some queries. This is usually not done via routing in CI. Also routing just points a URL to a controller and function and has little to do with url rewriting.
Why don't you want to use slugs?
You could try storing the search engine friendly route in the database using this method or this one.
I wouldn't recommend throwing a 404. Use the canonical link tag in the instead if your worried about Google indexing both http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html.
But if you really want to I guess you could write a function that is called during the pre_controller hook http://codeigniter.com/user_guide/general/hooks.html that checks to see if the URL has an integer as the second segment then call the show_404() method. Perhaps a better solution when writing this function would be to redirect to the SEO friendly version.
Is there a way (via routing) in CodeIgniter to change:
example.com/category/4 to example.com/category/foo-bar
where Foo Bar is the name of category 4 in the database?
Yes.
Using CI 3,
http://www.codeigniter.com/user_guide/general/routing.html
Use Callbacks, PHP >= 5.3
$route['products/([a-zA-Z]+)/edit/(\d+)'] = function ($product_type, $id)
{
return 'catalog/product_edit/' . strtolower($product_type) . '/' . $id;
};
You can route to call a function to extract the name of the category.
Hope I answered your question and can help more people to like codeigniter as I believe it's speedy and light.
Slugs usage is important to make web application more secure which i think is important.
A better recommendation will be to use route to give you a better solution.
$route['(:any)/method/(:num)'] = 'Class/method';
or
$route['(:any)/method/(:num)'] = 'Class/method/$1';
$route['(:any)/gallery/(:num)'] = 'Class/gallery/$1';
base_url()/business-services/gallery/6
base_url()/travel/gallery/12
how to modify routes in codeigniter
Have fun :)

Resources