Angular routing under wordpress site - php

I have a WordPress site where one of the pages that WordPress serve is an SPA based on AngularJS. The Angular-app uses html5mode so that I can browse to http://localhost/79133/71 and I'm still showing index.html. Now I want to deploy this to my WordPress site so that one of the pages under WordPress (the main page) is my SPA. However, if I browse to http://example.com/79133/71 WordPress will try to find the page with the permalink 79133/71 and won't understand that the main page should be served. How can i configure WordPress so that these new "routes" will be pointing to the first page?

I'm not an expert on WordPress, but in order to get html5mode to work in angular:
Any route starting with /your_spa needs to serve the main page (index.html) of your app.
You must ensure that any resources referenced in your spa (for example, /assets/themes/theme.css) needs to point to the correct location, even if your location url is your_spa/your/spa/page. This means no relative paths unless you use the base tag.
Here's a tutorial on how to configure the router in wordpress. I don't use wordpress so I'm sorry that I
It seems like a lot of trouble, and I would just use the default hash routes if possible.

I had the same basic issue, and solved it. Your situation is slightly different but I think you need something like:
function spa_rewrite() {
add_rewrite_rule('79133/71', '/', 'top');
}
add_action('init', 'spa_rewrite');
In practise you'll need to use some regex to make this more flexible

Related

loading a template in php

I'm building a small CMS in php but I have a problem with the front end. I have a folder name template inside the folder I got different themes
-admin
-template
---theme1
---theme2
---theme3
-index.php
when I load the index.php I can load the theme, but in the browser URL I get localhost/cms/template/theme1/page.php
but I like to have localhost/cms/page.php instead.
will you please tell me when I'm doing wrong!
Thanks.
I'm a little confused...you say this is a front end issue, but you point to the URL as the issue.
My guess is this: You need to identify different themes using separate stylesheets in CSS. Having different pages called page.php that looks differently definitely requires more work and complicates the issue. CSS was designed for you to customize the look of different pages and/or templates. Why not create 3 different stylesheets and then create a simple form that allows the administrator to choose which stylesheet to use (by radio button, or something else).
You can determine which stylesheet is "in use" in a number of ways - either on the back end or the front end. Given that this is a CMS, you'll probably want your administrators to choose the stylesheet and allow their selection to update a database entry or change a file on the back-end. No matter what you choose, you're URL's probably should not be affected.
Finally, you can rewrite URLs with .htaccess, but that can lead to more issues as you develop the site. Generally speaking - htaccess is overkill for issues like this.

Changinging Joomla template according to the url open in the browser, how?

I am asking if is it possible do the following thing using Joomla
I have 2 different URL, something like: www.stupidname.com and www.seriousname.com
If the user open stupidname.com by his browser will open the website having a stupid template
If the user open seriusname.com by his browser will open the website having a serious template
The website and the content are the same...should only change the template according to the url open in the browser
Do you have some ideas about how to do this thing?
Thanks
Andrea
I've done this before making elements of a template conditional based on the domain name, and that can work well. I suppose you could extend the same logic to change the template.
Perhaps you could add a conditional to both template's index.php to change the template. Perhaps something like...
if ( substr_count( $_SERVER['HTTP_HOST'], "silly") ) {
$GLOBALS["mainframe"]->setTemplate = "silly_template_name";
} else {
$GLOBALS["mainframe"]->setTemplate = "serious_template_name";
}
...I've not tested this, but I think in principle it should work fine, though it might depend on which Joomla version you have.
There are, as saji89 pointed out, plenty of good multi-site extensions and that'd be an ok solution too.
From my personal experience with Joomla I can advise you to use the component Virtual Domains (http://extensions.joomla.org/extensions/core-enhancements/multiple-sites/7557) you can add the domains which you redirect to the main site where Joomla is installed and it this component you assign them the template you want.
I can confirm the functionality on Joomla 2.5 latest update with usage of around 5+ different Virtual Domains on one Joomla installation.
Some possible downsides i want to mention:
SEO links can get sometimes messy, you need to play with some SEO component and its settings
its better to use same structure and components for boths side its easier because otherwise the administration gets messy but its possible
the user which register on one website has automatically account on all of them because its one Joomla

Wordpress custom Querystrings & Pretty URL's - How?

I have a perfectly good (so far) setup of wordpress of for a new website. The pretty urls are working as expected.
I have 1 dynamic page that loads content depending on the querystring:
/dynamic/?loc=england&code=uk
I wish to make this URL "pretty" as well but every-time I modify the .htaccess no changes are made. Tried everything and googled everything else - last resort. If I could get the following to work then I would be happy.
I need to make the URL look like.
/dynamic/location/england/code/uk/
Adding this to any .htaccess breaks the whole website.
RewriteRule /dynamic/(.*)/(.*)/(.*)/(.*)/$ /dynamic?$1=$2&$3=$4
What am i missing.
Thanks in advance
N
Don't add the rewrite rule to your .htaccess file. WordPress manages that file for you, so try to use built-in features whenever you can.
WordPress actually has a somewhat advanced rewrite engine that ships standard - and it's pluggable just like the rest of the platform.
The trick, though, is working with it. You'll need to register your RegEx so WordPress knows what kinds of strings to match (i.e dynamic/location/(.*)/code/(.*) => /dynamic?$loc=$1&code=$2). Then you'll need to set up the page and script on the back end to handle the submission.
For a similar example, look at the answer I received to parsing custom URLs with a custom post type over on WordPress Answers. Extending this, you'll need to set up code similar to the following (note: untested!!!):
<?php
add_action('init', 'add_my_rewrite');
function add_my_rewrite() {
global $wp_rewrite;
$wp_rewrite->add_rule('location/([^/]+)/code/([^/]+)','index.php?loc=$matches[1]&code=$matches[2]','top');
$wp_rewrite->flush_rules(false); // This should really be done in a plugin activation
}
This should add the rewrite structure to your .htaccess file automatically.

joomla fully customize component link

I made a component and now I want to customize the link for it.
I already wrote the router.php.
The link to the component view (if I use the JRoute function of course) now looks good, except for the first part, which looks like :
http://www.example.com/en/component/componentname/...
don't mind the "en", it's there cause I use JomFish to manage more languages on my site.
I want to transform "/component/componentname/" to "/myString/" for example.
I can't use the menu for this, cause my site displays info from a database, linking this many sites to my menu is impossible.
The only solution I found requires the changing of the Joomla JRoute function (I found only a suggestion, not how it's done :( ).
What about using mod_rewrite to rewrite your url?
Basically you put the rewrite rules into your .htaccess file and Apache will handle the rest.
There is a great guide that teaches you all about it on http://www.htmlist.com/how-to/a-simplemod_rewrite-tutorial/

Codeigniter, domain to a certain area of the site

I'm not a very experienced programmer, and am using CodeIgniter for second time.
Suppose I have www.domain1.com. So I will have, say 3 controllers /area1, /area2, /area3. Users can access them as www.domain1.com/area1 etc. if I set the base URL as www.domain1.com. But my problem is, the client wants a certain area of the web, say area2, working as a microsite, in its own domain, so he wants to access area2 with www.domain2.com.
I don't know how to get this working with CodeIgniter. Suppose he registers www.domain2.com and set it pointing to the same DNS, server etc. How can I get CodeIgnitor to execute the controller area2 when the URL www.domain2.com is accessed?
Maybe changing $config['base-url']? Routing? .htaccess? Please, if you have solved this, examples of code involved would be greatly appreciated.
Edit: I will put example of the site I want to get.
I have one normal installation of CodeIgniter (external host, I can't access httpd.conf) It is on one machine, and the root of the site should be accessed by www.domain1.com
All domain are outside registered to. So I have the home controller, which shows me the main page view. And suppose the site have 3 areas /area1, /area2 /area3, with their correspondent controllers, showing these areas views.
My client want to emphasize one of the areas, the one that controller /area2 shows, and he want use a different domain for that area, www.domain2.com
What can I do so that when the user browse to www.domain2.com, CI redirects them to www.domain1.com/area2? Could I, for example, modify $config['base_url'] according the received URL, or is that impossible? Do I need to modify the .htaccess file?
After a lot of searching, I found a solution that seems to work, very easy to be honest:
Modify routes.php:
if ($_SERVER['HTTP_HOST']=="www.domain2.com") {
$route['default_controller'] = "area2";
}
No need for mod rewrite.
Here's a helpful link....
http://www.askaboutphp.com/88/codeigniter-setting-up-multiple-sites-on-one-install.html
Never actually done this myself, but this seems to be the way to go about it without having two ci installs. Good luck.
you definitely need to go the mod_rewrite way
the first solution that comes to my mind is to use Apache mod_rewrite, but as far as I know that would work only for internal redirects (i.e. resources residing on the same server/domain).
What about using an iframe? You could set up domain2.com home page with a full-page iframe that takes it's content from domain1.com/area2.

Categories