I'm basically trying to reverse-engineer a site made in Wordpress. My peer made our site in wordpress, and I would like to add some code to processing data from a form using the Contact Form 7 plugin. When viewing source, the form action is
/v2/wp/index.php/contact-us/#wpcf7-f57-p9-o1
Also I noticed that all the URL's of the various pages have text after the .php, which I don't understand.
http://.../index.php/information-for-sponsors/
In the first case, I don't understand how the "/contact-us/..." is processed. In the second case, I don't understand how "/information-for-sponsors/" is processed.
To implement this you need to look down the mod_rewrite option for Apache. It allows you to map urls and can be combined with php to get what you need.
For instance, I write a blog software before which translated the url .com/contact/ to .com/index.php?key=contact
Then using the key in php I returned the post with the title contact.
Google Apache Mod_ReWrite, it takes a while to undertstand fully and you need this option enabled on your host. Many Free hosts dont have this functionality enabled.
Though all the comments and answers above are absolutely correct, I am not sure, however, if you will understand any of them correctly.
Well, this concept is called URL Rewriting and is used for a variety of purposes such as improving ranking in search results, making readable keywords,etc.
There are lots of plugins in Wordpress which do this dirty work for you and there is also the Wordpress Codex(if you wish to write your own).
For your reference, I found this blog which will explain this better.
Smashing Magazine Article
Related
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).
I'm not asking for a whole engine of code. I'm working on a blog/magazine website. Here are the 2 styles of paginations. I see people use these types of addresses:
example.com/browse?page=100
example.com/page/100/
I understand 1.'s. But, 2. doesn't give me an impression of php usage in the address.
I did a search on Google, but there are only helps on 1. How do you manage 2.? Because whenever you write a new article, you have to push the content throughout every html? Did they use "fake addresses"? because I tried example.com/page/100/index.html and there is no such website.
Can anyone point me to a webpage or explain to me how did they manage 2. style of pagination? Which has a better UX?
Sorry if this is a bad title. Please help me edit and ask me if anywhere isn't clear.
It's URL Rewriting that is responsible or translating nice-looking Urls to their 'real' path on the server.
In your case,
www.example.com/page/100/
might be rewritten on the server to something like
www.example.com/browse.php?page=100
More info:
mod_rewrite for Apache
Url Rewrite for IIS
I am struggling to find this as I'm not sure exactly what I'm looking for!
I've seen that some sites seem to use 'subfolders' as links to pages, e.g. wikipedia.
E.g. Let's say I had a record in a database with a unique title "My Shopping List". I want to be able to navigate to www.mySite.com/my_shopping_list and have it automatically 'forward' to a page showing the relevant record.
I am using IIS and wondering if there's a way I can do it with that, but I may be looking in the wrong place.
This is for a knowledgebase where I might write an article called "how to use a computer" and would like to be able to create a 'friendly' link for users (http://www.mySite.com/how_to_use_a_computer rather than http://www.mySite.com/article.php?ID=123. I will need to be able to create these 'links' dynamically using the title field.
Thank you
EDIT: I am using IIS6
You should use URL Rewrite, the microsoft ressource for this technique is here: http://www.iis.net/download/urlrewrite
In the iss forum the issue about url rewrite in iss < 7 is discussed with some suggestions on software to use.
I don't know which one is best, maybe there are others who know:
http://iirf.codeplex.com/
http://www.isapirewrite.com/
http://urlrewriter.net/
With PHP, you'll need to code URLConf using something like a htaccess file or the manager GUI. You can read ISS docs on URL rewrite to learn how., but as I understand, this is a module you'll have to download separately.
This question also shows how do do it without editing server configuration files or htaccess, but you'll be stuck with a http://example.com/index.php/path/to/view format (where index.php is a real script with the URLConf in it.)
Well some time ago it was used to call 'Friendly URL' or 'FURL', now i see that it's ust Rewrite URL. Look for tutorials for beginners.
So, currently I'm organizing my blog based on filename: To create a post I enter the name of the file. As opposed to storing the post in the database, I store them in PHP files. So each time I create a post, A new row in the table is created with the filename and a unique ID. To reference the post (e.g. for comments) I get the name of the current file, then search the entries table for a matching file name. The post ID of the comment matches the ID of that post.
Obviously this isn't the standard way of organizing a blog, but I do it this way for a few reasons:
Clean URL's (even cleaner than mod_rewrite can provide from what I've read)
I always have a hard copy of the post on my machine
Easier to remember the URL of a specific post (kind of a part of clean URL's)
Now I know that the standard way would be storing each post in the database. I know how to do this, but the clean URL's is the main problem. So now to my questions:
Is there anything WRONG with the way I'm doing it now, or could any problems arise from it in the future?
Can the same level of clean URL's that I can get now be achieved with mod_rewrite? If so, links are appreciated
I will be hosting this on a web host. Do only certain web-hosts provide access to the necessary files for mod_rewrite, or is it generally standard on all web-hosts?
Thanks so much guys!
P.S. To be clear, I don't plan on using a blogging engine.
As cletus said, this is similar to Movable Type. There's nothing inherently wrong with storing your data in files.
One thing that comes to mind is: how much are you storing in the files? Just the post content, or does each PHP file contain a copy of the entire design of the page as opposed to using a base template? How difficult would it be to change the design later on? This may or may not be a problem.
What exactly are you looking for in terms of clean URLs? Rewrite rules are quite powerful and flexible. By using mod_rewrite in conjunction with a main PHP file that answers all requests, you can pretty much have any URL format you want, including user-friendly URLs without obscure ID numbers or even file extensions.
Edit:
Here is how it would work with mod_rewrite and a main PHP file that processes requests:
Web server passes all requests (e.g., /my-post-title) to, say, index.php
index.php parses the request path ("my-post-title")
Look up "my-post-title" in the database's "slug" or "friendly name" (whatever you want to call it) column and locates the appropriate row that way
Retrieve the post from the database
Apply a template to the post data
Return the completed page to the client
This is essentially how systems like Drupal and WordPress work.
Also, regarding how Movable Type works, it's been a while since I've used it so I might be wrong, but I believe it stores all posts in the database. When you hit the publish button, it generates plain HTML files by pulling post data from the database and inserting it into a template. This is incredibly efficient when your site is under heavy load - there are no scripts running when a visitor opens up your website, and the server can keep up with heavy visitation when it only needs to serve up static files.
So obviously you've got a lot of options when figuring out how your solution should work. The one you proposed sounds fine, though you might want to give careful consideration to how you'll maintain a large number of posts in individual files, particularly if you want to change the design of the entire site later on. You might want to consider a templating engine like Smarty, and just store post data (no layout tags) in your individual files, for instance. Or just use some basic include() statements in your post files to suck in headers, footers, nav menus, etc.
What you're describing is kind of like how Movable Type works. The issues you'll need to cover are:
Syndication: RSS/Atom;
Sitemap: for Google;
Commenting; and
Tagging and filtering content.
It's not unreasonable not to use a database. If I were to do that I'd be using a templating engine like Smarty that does a better job of caching the results than PHP will out of the box.
I have recently taken on a php web developer position for a large firm. They have multiple sites that share much of the same content (mainly news articles). All the sites although written in PHP, the content is static and manually edited on all the sites when a news article is added or other information is changed. The "senior programmer" there is against using a cms for some reason, against upgrading to php 5, against installing mod_rewrite, basically I have to work within a very small parameter.
I have taken the first 3 weeks to write a whole lot of classes to make some sort of sanity out the mess, but I have to find a way to replicate this data in an easy manner. I am thinking something without the need of a database (the head guy doesnt want to decentralise data so databases anywhere other than the intranet are a no-no), I just want a centralised XML file or something, even if I need to hand edit it... any ideas???
Treat PHP as a templating engine, and have all the main pages pull the html marked up (or xml) articles from an RSS feed from one site.
Edit the feed to add a new article, add the marked up article to the main site, and it's all very, very simple, easy to understand, and scales.
No need to involved a 'real' cms, database, or anything.
-Adam
User one folder for all documents which your websites consume.
You could use CURL to access what you need over HTTP. Setting the CURLOPT_RETURNTRANSFER option to 1 will allow you to get whatever content you would like. XML, HTTP, etc.
Have one master site, on which the original content is created & edited.
On all others, use the Apache ErrorDocument handler in .htaccess to route 404 errors to a new php script.
ErrorDocument 404 /syndicate.php
In syndicate.php, take the uri (from $_SERVER['REQUEST_URI']), fetch the contents from the original domain and output it with a 200/OK header (so it's not seen as a 404).
$master_domain = 'http://master.com';
$master_html = file_get_contents($master_domain . $_SERVER['REQUEST_URI']);
if($master_html != '') {
header("HTTP/1.0 200 OK");
echo $master_html;
} else {
header("HTTP/1.0 404 Not Found");
}
The duplicate content will still be under the requested url.
If the senior programmer is against industry standard tools like CMSes, PHP5 (at least when considered against PHP3/PHP4 - no need for a language holy war), mod_rewrite, etc. it's time to involve management. Such an attitude is unacceptable.