I wanted to document some of the issue’s I’ve had whilst creating this site and for the first one it’s worth talking about CodeIgniter, htaccess files and how they do (or don’t) work on shared hosting.
htaccess files are great - there are all sorts of fantastic things you can do with them. One of the things I’m using htaccess files for on this site is to convert SEO unfriendly blog urls, such as http://planetcjd.co.uk/blog/read/9 into the slightly better http://planetcjd.co.uk/blog/read/a-test-for-the-road/9 style urls complete with keywords that hopefully that Google and co. can pick up on.
In theory this is quite easy, all you need is a .htaccess file with:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index.php/blog/read/[^./]+/([0-9]+)(/)?$ index.php/blog/read/$1
</IfModule>
All that’s doing is identifying a fake additional part of the url, ignoring it and rewriting to the proper url. I’m using that ‘ignored’ part and putting the title of each blog post into it.
In practice this worked on my testing server. However on this web server, my shared hosting server, that rule just throws up a nice helpful “No input file specified” message.
After much googling and trial-and-error testing the reason this doesn’t work is because my shared host runs PHP in CGI mode rather than as an Apache module. Rewriting the url causes a problem that prevents the PHP interpreter from invoking the correct file. You need to move part of the url into the url’s query string my adding one little ‘?’ (question mark) after the new url’s ‘index.php’:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index.php/blog/read/[^./]+/([0-9]+)(/)?$ index.php?/blog/read/$1
</IfModule>
You should now have working SEO friendly urls!
Related posts:
- Implementing the Metaweblog API in PHP - handling multiple categories
- Implementing the Metaweblog API in PHP - getting started
- Quick Tip: Things to try when PHP"s json_decode function doesn"t work
php web codeigniter
|
irhmgbGV
Posted 2 Days ago
|
|
||
|
NedXendy
Posted 2 Weeks ago
|
|
||
|
NedXendy
Posted 2 Weeks ago
|
|
||
|
NedXendy
Posted 2 Weeks ago
|
|
||
|
NedXendy
Posted 2 Weeks ago
|
|
||
|
buyviagrai
Posted 3 Weeks ago
|
|
||
|
Erowndrobby
Posted 3 Weeks ago
|
|
||
|
Choivaviore
Posted 1 Month ago
|
|
||
|
UtewotaAttepe
Posted 1 Month ago
|
|
||
|
Borlidak
Posted 1 Month ago
|
|
||
|
teamsportdirect
Posted 2 Years ago
|
|
