Dynamic directories and files like wordpress - php

In wordpress there are directories which actually do not exists.
like example.com/post/name-of-the-post actually opens a main php file which fetches the content of that posts from database.
How can i implement this natively on linux apache php server without wordpress?

You need to use .htaccess. This is the technology behind Wordpress' ability to do what you are wanting to do.
Here are the docs from apache.
Also here's a nice Tutorial

I don't know why people use mod_rewrite, it is overkill for most tasks. For most things there are more nimble modules available. That is not to deny mod_rewrite, it has its place, but I find it is over used. In this particular case you can use mod_alias, no need for mod_rewrite. E.g.
AliasMatch ^/post/(.*) /real/path/post.php$1
module docs here: https://httpd.apache.org/docs/2.2/mod/mod_alias.html
This doc beautifully outlines when NOT to use mod_rewrite: http://httpd.apache.org/docs/current/rewrite/avoid.html

Related

URL pattern matching in PHP

I'm trying to implement java like url pattern matching in php. Suppose i have a link which leads to a file called find.php (Example is shown below)
http://www.xyz.com/MyWebsite/TryToFind/find.php?search=abc+def
Then i want to expose the follwing link to the users, say,
http://www.xyz.com/Search?search=abc+def
then i want to match this(2nd url pattern) url to the one i have provided above(1st url pattern) using a controller. This is because i want to hide the exact uri pattern to the user and also the hide the extension which i have used.
Please Help Me Guys...
Regards,
Abilash
If you are using apache (which I assume you are as you have tagged .htaccess) as your http server then you can use Apache's Mod_Rewrite Module. It usually ships with most installations of Apache these days and anyways you can install one yourself if it is not present.
Mod_Rewrite will enable you to achieve what you desire, In fact it is designed for that purpose only. While php frameworks like CodeIgniter provide some programming support for Mod_Rewrite, working directly with .htaccess using the Regex will render you with more power and flexibility.
A full explaination is difficult here. But this was the tutorial I found handy when learning the same.

Wordpress .htaccess Modification

I have a site with this structure:
Home
About Us
Products
Product
Services
Contact
If I open
mysite.com/products
reads page-products.php
and
mysite.com/product
reads page-product.php
I need to use page-product.php as a generic page.
For Example...
mysite.com/product/The-Best-Product/32
read page-product.php?name=The-Best-Product&id=32)
And how about
mysite.com/john/
and reads page-user.php?username=john
Its possible to make something like that works?
Thanks!
Consider using the Apache Web server's mod_rewrite, which is a very powerful tool to do just what you need. This would only help you if you are using Apache. Also, if you are not the Webmaster, mod_rewrite must have been enabled for use in .htaccess files.
The bottom of the page I linked has some examples on how to use this. Also, there are many tutorials around.

How to make use mod_rewrite to create pretty permalinks for a custom-built CMS PHP script meant for external distribution?

I am trying to build a CMS that will be used by other people, which means that I can't rely on editing the .htaccess files for mdo_rewrite. I have looked up methods for mod rewriting urls from http://example.com/index.php?category=food to http://example.com/category/food but most of them seem to rely on apache and editing the .htaccess file, which would only work if you are creating a script which, like public scripts like Wordpress, rely on being installed on an external user's server. How do I mod_rewrite from within the script so that the script either automatically edits the user's mod_rewrite settings in .htaccess (as in altering the rewrite rule in the file from within the script itself) or some other method that would work fo a CMS script that is solely written in PHP and intended to be used on another server.
If the script you are using, is making use of a popular framework, chances are they have installed a so called "routing" system inside the framework. That by itself allows nice URLs.
In fact, if you're using any commercial script for a webshop or something alike, they probably have a mod, plugin or component that allows nice URLs. Look it up or add additional info please. :-).

PHP URL 'Redirecting'

Say if you visit my site: http://nesmods.com/page/2/ there isn't actually a /page/2/ on my site, Wordpress somehow catches the URL and generates a page based on the URL. What is the name of this technique?
This redirecting is managed by the mod_rewrite Module of Apache. Normally this is done in the .htaccess file. Depending on the configuration of your FTP program you can see them as hidden files in the Wordpress root directory.
Some further explanations and examples: http://www.workingwith.me.uk/articles/scripting/mod_rewrite - and Google of course.
Clean URLs apparently. Often done through .htaccess files.
There are a few ways to do this, referred to as URL routing or URL rewriting. Wordpress uses URL routing to map URL structures to it's internal functions that generate content.
It can also be done with the web server itself, such as URL Rewriting with Apache mod_rewrite
Apache hava a module of rewrite url。
It is a good search engine optimization。
This is a detail info about rewrite http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

Rewrite index.php in Wordpress

I started a blog and when I changed my permalink structure to /%postname%/ I get a Page Not Found error. I want my url to look like this:
http://bobbybeckner.com/sharepoint-list-and-linq-using-jquery-and-ihttphandler/
not this:
http://bobbybeckner.com/index.php/sharepoint-list-and-linq-using-jquery-and-ihttphandler/
I read a few posts about changing .htaccess but found no clear solution. Any code examples welcome or recommendations on wordpress plug-ins would be greatly appreciated.
Update
I thought it would be important to mention that my host is running IIS7 but does not allow users to touch it. In addition, I'm uncertain of any restrictions on the .htaccess file or any other configuration limitations.
.htaccess files only apply to Apache (well, maybe some other servers use it too, but not IIS). AFAIK URL rewriting for IIS is possible, but not as easy.
ISAPIRewrite appears to be a commercial application that does this, but of course, you'd need to get it installed on your server.
Personally, I wouldn't lose any sleep over having /index.php/ in your urls.
Generally when you fill out the structure, if the .htaccess file is writable it will apply the rewrite for you, and if it isn't it will show what the contents should be at the very bottom of the page. Did you check the bottom of the page if it is not writable?
You do NOT have to code this yourself.

Categories