TobesC Posted August 11, 2008 Share Posted August 11, 2008 Hey everyone - does anyone know what kind of code to write so that a page is created with the title of the article so that it can get crawled by Google? For example, when I read an article on wordpress the page comes up as ../this-is-the-article/. Thanks. Quote Link to comment Share on other sites More sharing options...
tibberous Posted August 11, 2008 Share Posted August 11, 2008 Generally, you use what is called a rewrite rule, with is done through the mod_rewrite extension in Apache. Alternatively, you can use custom 404 pages - I'm sure there are other methods for non-Apache setups. http://www.flashgamereviews.com/Bloons-Tower-Defense-2-Review.html Done by... RewriteEngine On RewriteRule ^([A-Za-z0-9\!&-])+\.html$ index.php in the .htaccess file Little word of advice, these are HARD to write. There a bitch to debug, act funny when you chain them, and require regex which you don't know. Quote Link to comment Share on other sites More sharing options...
Johntron Posted August 12, 2008 Share Posted August 12, 2008 I think you may be asking about Search Engine Friendly (SEF) URLs in Wordpress (which the folks at Wordpress call "permalinks"). I'm not sure when the feature appeared, but you can specify the permalinks for each article (see attachment) [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
TobesC Posted August 12, 2008 Author Share Posted August 12, 2008 hey - thanks for the responses. exactly what i wanted, but i want to know how to do them for my own site. any help is appreciated. thanks. Quote Link to comment Share on other sites More sharing options...
Johntron Posted August 13, 2008 Share Posted August 13, 2008 I'm not sure if this is the only solution, but this is how I always see it done . . . in you .htaccess put: RewriteEngine on RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php This will redirect requests to everything other than media files (files with extensions: js, ico, gif, jpg, png, and css) to index.php, internally. In index.php, you would then parse the $_SERVER['REQUEST_URI'] variable and run the appropriate code. A sample request: 1. User opens browser to http://www.domain.com/posts/how-to-use-modrewrite/ 2. Apache (specifically, mod_rewrite) notices that this is not a media request, so it runs index.php. This does _not_ perform an HTTP redirect. 3. index.php parses $_SERVER['REQUEST_URI'] and runs some code to generate some output, which is then sent back to the user. This process of parsing an HTTP request, and deciding which code to run is commonly called the Router design pattern. The index.php file could be said to use the Front Controller design pattern. Here's a very simplistic example of what your index.php file might look like: <?php // Assume the user requested: http://www.domain.com/posts/how-to-use-modrewrite/ if ( 0 === strpos( $_SERVER['REQUEST_URI'], '/posts/' ) ) { // User wants to do something with blog posts, so instantiate the Blog class $blog = new Blog(); $title = substr( $_SERVER['REQUEST_URI'], 7 ); // Strip out the title; 7 is the position in the string that the title starts $content = $blog->getContentByTitle( $title ); include 'postTemplate.phtml'; // This file would consist of mostly HTML, but would also echo $title and $content at some point // closing php tag is not necessary here and should be left out, but that's a whole other topic This is untested code, but you should get the basic idea. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.