I try to design a web in different languages.
How can make the link that gives a clean url? Some pages are dynamic so, I do not know the url, I am searching for a way to make that links work in any page.
I know I can do this because it works in any page:
<a href='?lang=en'>en</a>
<a href='?lang=fr'>fr</a>
But, how to do that and be able to get a clean url like this?:
myDomain/someFolder/file.php // the default in English
myDomain/fr/someFolder/file.php // fr for French
(Beware that it is not just change fr to en. In English there is no /en/)
I have found that I have tu use a rewrite rule in the htaccess to change from myDomain/someFolder/file.php to myDomain/Folder/file.php?lang=en But this is not the point, my question is different, I ask: how to make clean links in the html if I do not know the url?
What I would do, which is not anywhere as fancy as an .htaccess rewrite tool...
First, I would do something to get the current page name. This can be as simple as:
$pagename = "contactme.html";
Now, I have an array of available languages:
$languages = array('en'=>'English','fr'=>'French','es'=>'Spanish');
With that, I can slap this on the top of every page:
Select your language: <?php
foreach($languages as $ln=>$language)
print " <a href='mysite.com/$ln/$pagename'>$ln</a> ";
That will spit out a list of abbreviations. Can they be little flags (a lot of people like those). Sure. Change $ln in the anchor to <img src='$ln.png' border='0'> and make sure you have all the images. Can they be in a form with a select list? Sure. Make a select list. Add an 'onchange' trigger to the form to reload to the correct URL. Can they be is a super-fancy rotating flash animation? Yes - if you really want to do something that silly.
Related
I have a two language setup, structured like this:
includes/languages/lang-it [has the defines]
includes/languages/lang-en [has the defines]
includes/languages/languages [has the languages array]
en/files
en/subs/files
it/files
it/subs/files
I have en/sub-1/index.php and en/sub-1/file-1.php and need to be able to change language when in file-1.php page
This is the code I have, and of course it does'nt work
require("../../includes/languages/lang-en.php");
link to file-1 English
link to file-1 Italian
Where LANG_ENG and LANG_IT are the directories (en and it)
So I need it to pick the includes/languages/lang-en.php for the the English, and includes/languages/lang-it.php for the Italian.
I guess I need to "require" the correct language file before "LINK-1", but don't know how.
I solved it like this:
Added $thispage, added variables for the file-name, and put that in the link.
Perhaps there are better ways, but that's what I could think of, and is working.
<?php require("../../includes/languages/lang-en.php");?>
<?php // variables for pages to use for language links
$file_1_en="file-1-en.php";
$file_1_it="file-1-it.php";
?>
<?php if ($thisPage=="page name")
echo'
'?>
I have a website which is used for ads listings like backpage and craigslist.
I have inserted a Banner Ad on every sidebar on every city: for example the banner image filename is
myimage.jpg
now what I want to happen is: whenever they visit a city (for example mysite.com/boston), I want the filename to be like this:
src="myimage-boston.jpg"
and when they visit
mysite.com/birmingham
the image filename will be
src="myimage-birmingham.jpg"
I'm doing this for SEO purposes. I hope I've explained it well. Thank you in advance :) btw im using codeigniter.
Googlebot couldn't crawl this URL because it points to a non-existent page. Generally, 404s don't harm your site's performance in search, but you can use them to help improve the user experience.
If you can use mod-rewrite, try this rewrite rule in Apache server config .htaccess or httpd.conf (if you have images in /images path):
RewriteRule ^images/(.*)-.*\.jpg$ /images/$1.jpg
After that, you can substitute image src for anything you want:
<img src="/images/<?=$imageName."-".$whateverYouWant.".".jpg";?>" />
And the rewrite module will substitute it for /images/$imageName.jpg
Assign the __CLASS__ magic constant to your view, and you should know wich controler is being called.
more info here:
http://php.net/manual/en/language.constants.predefined.php
its should look like something like this:
$mydata['class'] = strtolower(__CLASS__);
and on your view
src="myimage-<?php echo $class; ?>.jpg"
The solution is simple, use javascript. U can access the URL via document.location. Then say detect the name of city using regex or substring and create image name dynamically.
This can also be done on the server side. But Javascript is better for a job like this.
Not sure if this is possible but wanted to know if htaccess has a trick...
Say I have anchor tag href like this -
Click here
I have changed the URL structure using mod_rewrite but wanted to know if i can hide the actual URL in href using htaccess.
i.e when a user hover over the anchor tag, the browser displays http://example.com/index.php?id=12345 at the bottom. All I want the browser to display is http://example.com/index/12345 without changing it manually on all my pages.
Thanks for the help !
Why don't you change the link to the following?
Click here
As you can change the .htaccess I expect that you own or adminstrate this domain. So it should be possible.
If the links are generated by PHP code, then I suggest you to implement and use a translation function like:
function beautify($ugly) {
// your logic comes here
return $nice; // ;)
}
... and wrap it around the existing code that currently outputs the urls. This would have two advantages:
It's easy and more failsafe to migrate to the new url scheme
From now on you have control over all url related code using a single function
I agree, htaccess can't help you. I guess you'll have to change them manually.
I wish I could be of more help
No. htaccess is for processing input to the web server, not data sent back from the server.
If you use jQuery you could have it rewrite the href when the page loads using something like this.
$(function(){
$("a").each(function() {
this.href = 'some_new_url that you made based on the one in this.href';
});
});
Okay, first off, I am not well-versed in JS or PHP. I can usually change an existing script around to do what I'd like, but not write something from scratch. Any URLs I mention in this for examples are made-up.
With that in mind, I am designing a page using a template that has CSS, PHP, and JS all of which I have really modified. Each page has a header, a nav bar, and a footer that are called with an include statement. I understand that part. However, on ONE of the pages, I would like to have a different nav-bar, and it won't change.
What I have noticed: The JS seems to change the clicked URLs from, say http://www.example.com/test.php to http://www.example.com/#test.php
What would be the purpose for that? Also... if I manually TAKE OUT the hashtag in the URL on the page that I want the new nav-bar, the new nav-bar shows! However, then if I switch pages, it'll make the end of the URL like ...test.php#newpage.php
So I either need to figure out how to modify this to NOT put the hashtag in the URL (but if there is a compelling reason for it, of course, it can stay), OR how to get that one page to show the alternate nav-bar. The alternate nav-bar is a table of contents, so the html has hashtags in it to direct users to specific parts of the page... could those hashtags in the html be conflicting somehow and that is why it won't show up, or??? GAH!
Any help would be appreciated.
Okay, here is part of the javascript... it is the only section where it looks like it is referring to # in the URL:
var $fadeWrapper = $("#fade-wrapper"),
$allNav = $("#main-nav a"),
$allListItems = $("#main-nav li"),
url = '',
liClass = '',
hash = window.location.hash,
$ajaxLoader = $("#ajax-loader");
$("body").attr("id", "");
if (hash) {
hash = hash.substring(1);
liClass = hash.substring(0,hash.length-4);
url = hash + " #inside-content";
$fadeWrapper.load(url);
$("." + liClass).addClass("active");
} else {
$("#main-nav li:first").addClass("active");
}
*UPDATE: I have decided to just remove the javascript altogether. In doing some reading, I have come to the conclusion that the hashtag is there just so the script can tell which page is active, in order for the CSS to highlight one of the items in the navbar. It also has something to do with the animated gif that would show when you navigate pages. Neither one of those items are important enough for me to pull more of my hair out trying to figure out this stuff :D Thank you for your suggestions, though! *
The hash tags are added most likely because the links you are clicking have an href value of #.
Couldn't you just create a new header file (if that is where the navbar code is), modify the navbar how you want in that header file, and include the new file instead of the current header on the page where you want the different navbar?
i think this question is very easy but I don't know if i am right.
I am an oldschoool html, php coder.
I want to use this kind of navigation:
http://www.cssportal.com/horizontal-menus/13styles.htm
So far no problem. I got an dynamic php page and i want to use this Menu.
There is no problem without this line in the HTML Part:
<li><span>LINK</span></li>
The Problem is the class. What is the smartest way to detect which link is now current?
I would do it in this way. I would write a php script like this pseudo code:
if acutaldocument == "link1.html" then echo "class='current' ";
But i think this is not the smartest way. Or am I right?
Thanks
There's many options...
You can use session cookies, JavaScript, you can pass an id on the end of the url (eg. ?nav=2) or parse the URL and check against it...
All of them work... all of them have there pros and cons... just depends on how your page is set up...
Give each page's body tag an ID. Say, you give the About page's body tag the id "about". Give IDs for all your navigation <li>s too. Say, you give "about" id to the navigation <li>
In your CSS file, do this:
body#about li#about {
// apply differentiating style here...
}
You can keep doing that for all other pages also. And only when both the body ID and the <li> ID match, the style is applied.