Forum Moderators: phranque
I have an old .htaccess which worked fine until I changed my hosting from shared to private. the host is still the same just a new server. here is the old file that was working
********************************
AddHandler server-parsed .php
<Files ~ "^[^\.]+$">
SetHandler application/x-httpd-php
</Files>
AddHandler application/x-httpd-php .php
********************************
It is over 5 years old so alot has changed in the mod_rewrite() world.
After the move to new server, all .php files load just fine. Any files that have to be rewritten load a blank page or an error page(depending on browser) I have an option in the admin section of the script to turn "Search engine Firendly" url's on or off. If I turn it off all links work fine but of course I get the ugly php pages and since I have .html pages that have been indexed for 4 years out there, people will get lots of errors.
How do I edit the above to work on the new server? The new server now gives me an option to turn mod_php 4 or 5 on of off in the c-panel. Any help will be appreciated. Thanks
The only thing that is there is the first line, which tells the server to parse any requested URL which does not contain a period (e.g. extensionless URLs) for PHP includes. But those URLs would still have to be resolved to an existing filepath somehow, and I see nothing that would do that.
It would appear that some of the original code has been lost or deleted. Or perhaps it was in an .htaccess file in a subdirectory, and that .htaccess file is now missing.
Jim
Anyway will post findings currently on the road
Plan B....
I have decided to come up with a new mod_rewrite, that could deliver friendly URL requests.
Here is what I have.
My whole new server is set to mod_php version 5.2.x. Domains using php as cgi pretty much
ignore this setting
I host several domains on that server but I can change any of the individual domains to use any
of these PHP settings
PHP 4.4.X
PHP 5.2.x
mod_php 5.2.x
The script I am trying to modify is the only script on its own domain.
Here is what I am trying to achieve. Use mod_rewrite to deliver friendly URL requests. Below are example of actual URL's and what they would look like under friendly terms. I have both Categories and Articles within those categories just to give a better idea.
CATEGORY NAME: Is Disco Dancing Still in
Actual ULR>>> www.mydomain.com/category.php?cat_id=8
Wish to be>>> www.mydomain.com/category/is-disco-dancing-still-in-8-9.html
CATEGORY NAME: Monkey TV Reviews
Actual ULR>>> www.mydomain.com/category.php?cat_id=30
Wish to be>>> www.mydomain.com/category/monkey-tv-reviews-30-1.html
CATEGORY NAME: Dancing Advantages
Actual ULR>>> www.mydomain.com/category.php?cat_id=14
Wish to be>>> www.mydomain.com/category/dancing-advantages-14-1.html
ARTICLES
ARTICLE TITLE: Vacations in Arizona
Actual ULR>>> www.mydomain.com/articles.php?art_id=254&start=1
Wish to be>>> www.mydomain.com/article/vacations-in-arizona-254-1.html
ARTICLE TITLE: Dancing in Puerto Rico
Actual ULR>>> www.mydomain.com/articles.php?art_id=222&start=1
Wish to be>>> www.mydomain.com/article/dancing-in-puerto-rico-222-1.html
ARTICLE TITLE:PHP Scripting Doomsday Looming
Actual ULR>>> www.mydomain.com/articles.php?art_id=1697&start=1
Wish to be>>> www.mydomain.com/article/php-scripting-doomsday-looming-1697-1.html
Thanks Again guys
The "friendly" URL carries the category or article number and also the title of the page, which is not actually used to deliver content (more on this later). Article URLs additionally carry a start page number.
Taking the more-complicated of the two, you'd need a rule like this in example.com/.htaccess:
# Internally rewrite /article/<title>-<article-ID>-<start-page>.html URLs
# to /articles.php?art_id=<article-ID>&start=<start-page> script filepath
RewriteRule ^article/([^\-]+-)+([0-9]+)-([0-9]+)\.html$ /articles.php?art_id=$2&start=$3 [L]
Once you get the basic function working, it's important that URLs with invalid or bogus titles are either rejected with a 404-Not Found or 301-redirected to the correct URL. This includes any deviation at all in the URL's characters, punctuation, or case. Be sure to test this, and add that functionality if it is missing.
If you ignore the "title" field of the URL, then the potential exists for massive duplicate-content problems, either accidentally- or maliciously-created. Because the title field in the URL doesn't affect the rewrite to your scripts, the RewriteRules don't care whether it is valid or not, and in fact have no way to "know." So your script must check this value to determine whether it's valid as-is, can be fixed-up and 301-redirected to the correct URL, or must result in a 404-Not Found response.
If you have no other RewriteRules in your .htaccess file, you will need to add either both of these lines or only the second one before any RewriteRules:
Options +FollowSymLinks
RewriteEngine on
Jim
Seems like anything with "article" ID in it or "category" ID will resolve. If any of those are missing it is going to 404.
Did you say I could add something to redirect?
You could modify the RewriteRule to go ahead and pass the articleID to the script for checking -- that's one way to do it:
RewriteRule ^article/(([^\-]+-)+)([0-9]+)-([0-9]+)\.html$ /articles.php?art_id=$3&start=$4&[b]title=$1[/b] [L]
Alternately, you could check the Request_URI variable from within PHP, and parse out the article ID using a regular-expressions construct like the one shown here.
In either case, require an exact match to return content. Otherwise, output a server response header of Status: "301-Moved Permanently", and another one of Location: containing the canonical URL as previously looked-up in the database. I'm not sure how PHP handles these two headers; Status is handled a bit differently than Location. You should be able to readily find examples, though.
Jim