Erik Andersson wrote:
Hi!
I need to translate the path
/category_name/sub_category_name/
to
/category.php?sub_category_id=2
without redirecting the user.
There seem to be many ways of doing it, but with my current web hosting
provider (E.N.E IT - www.eneit.com) there are some constraints. For example
I cannot modify the httpd.conf.
However, I've got the functionality provided by CPanel (e.g. AddHandler's)
and I can create .htaccess files.
I've read a little about the RedirectRule command in Apache, but it does not
seem to work due to that I'm on a shared hosting server.
I've also realised that I could do
/category.php/category_name/sub_category_name/, but haven't found a way to
remove the .php in that instance.
I'm basically looking for the most basic solution...
I recently did this on a couple webpages. Now my dynamic pages are being
crawled by Google (which was why I did it).
I wrote a .htaccess file with the following in it:
Redirect 301 /misc_fark.php
http://www.glassgiant.com/misc_fark/
Redirect 301 /gb_view.php
http://www.glassgiant.com/gb_view/
Redirect 301 /misc_gallery-album.php
http://www.glassgiant.com/misc_gallery.php
<Files misc_gallery-album>
ForceType application/x-httpd-php
</Files>
<Files misc_fark>
ForceType application/x-httpd-php
</Files>
<Files gb_view>
ForceType application/x-httpd-php
</Files>
Then I changed the names of the files to leave off the .php (so it looks like a
directory). Note: the redirect statements are there to help the search engine
find the new pages and to point people following old links to the right
location.
Then I exploded the $_SERVER['REQUEST_URI'] into an array using "/".
Now, instead of using $_GET['id'] on page
http://mydomain.com/misc_fark.php?id=3
I use $myarray[2] on page
http://mydomain.com/misc_fark/3/
This is not the ideal situation, but it works well and is much easier than
messing around with mod-rewrite. It does require that you can make your own
..htaccess, though. But if you can't, chances are you don't have access to
mod-rewrite either. You may have a .htaccess file already - make sure you don't
overwrite it if you do.
PS - Looking at the .htaccess file above, it occurs to me that I could probably
include all the files to ForceType in a single Files tag, but I'm not sure.
Good luck,
Shawn
--
Shawn Wilson
sh***@glassgiant.com http://www.glassgiant.com