473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Search engine friendly URLs

I've been trying to use .htaccess to get Apache to recognise 'article'
as 'article.php' so I can have search engine friendly urls in the form
article/var1/var2/var3 etc

I have this in a .htaccess file

<Files article>
ForceType application/x-httpd-php
</Files>

This works fine on my test server but for some reason my host server
(choice is out of my control) will not allow me to upload a .htaccess
file.

Is there another way of doing it?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Nov 24 '06 #1
4 1581
Message-ID: <r4********************************@4ax.comfrom Geoff
Berrow contained the following:
>I've been trying to use .htaccess to get Apache to recognise 'article'
as 'article.php' so I can have search engine friendly urls in the form
article/var1/var2/var3 etc

I have this in a .htaccess file

<Files article>
ForceType application/x-httpd-php
</Files>

This works fine on my test server but for some reason my host server
(choice is out of my control) will not allow me to upload a .htaccess
file.
The file was uploaded, it was just hidden. Unfortunately it still does
not work. mod_mime is loaded so I'm now at a loss to know what to do
next.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Nov 24 '06 #2
Hey Geoff,

One if the cleanest ways to setup a site is to use mod_rewrite in
Apache. I am going to show you a simple way to do this using an
htaccess file and a little PHP. First step is to make an htaccess file
with the following code:

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?loc=$1

Now everything that is not a folder or a file will get passed to the
index.php file as $_GET['loc']. You could change the index.php to any
file you like and the ?loc= to some other variable if you like.

Next you need to groom the url. Do not leave out this step. You are
injecting the url into your script... I suggest something solid like
the following:

<?php
$url = preg_replace('/[^[:alnum:]\-\/]/', '', $_GET['loc']);
?>

So now you have the url into your script safely so you need to break it
apart. You are basically going to pass variables here. All you have to
do is explode on the forward slash. You can do it simply like this:

<?php
$parts = explode('/',$url);
$section = $parts[0];
$subsection = $parts[1];
?>
Hope this helps!

http://www.bradino.com/apache/mod-rewrite/

BRAD

Nov 24 '06 #3
You may want to check out this article as well:

http://www.alistapart.com/articles/succeed/

good luck!

Nov 27 '06 #4
Message-ID: <11**********************@h54g2000cwb.googlegroups .comfrom
jopperdepopper contained the following:
>You may want to check out this article as well:

http://www.alistapart.com/articles/succeed/

good luck!
Thanks for that. I've now managed to get the first method I posted to
work (It didn't due to my stupidity in reading the instructions...) It
feels like an instinctively better way of doing it. Instead of passing
everything that is not a file to a script (or in your example passing
everything to a script) the ForceType method is specifically targeted.

The method is this: a php file is saved /without an extension/. Let's
say the file is called articles. The following is placed in .htaccess

<Files article>
ForceType application/x-httpd-php
</Files>

This causes Apache to treat our extensionless file as a php file. The
URL produced just looks like a series of directories e.g.
/article/news/local

Obviously the directories do not exist.
Apache has the feature of looking back up the URL till it comes to
something it recognises - in this case our file article. article
contains code to extract the variables from $_SERVER['REQUEST_URI']

http://www.ckdog.co.uk/article/news/local
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Nov 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: phpkid | last post by:
Howdy I've been given conflicting answers about search engines picking up urls like: http://mysite.com/index.php?var1=1&var2=2&var3=3 Do search engines pick up these urls? I've been considering...
0
by: R. Rajesh Jeba Anbiah | last post by:
Q: Is PHP search engine friendly? Q: Will search engine spiders crawl my PHP pages? A: Spiders should crawl anything provided they're accessible. Since, nowadays most of the websites are been...
0
by: Shabam | last post by:
I'm interested in converting dynamic urls to something that looks static so that they're more search engine friendly. Instead of www.domain.com/script.aspx?userid=1234 I'd like to have it as...
4
by: moondaddy | last post by:
I've made the decision to use search engine friendly URLs in my site which means translating stripping all parameters our of the URL and converting it to a hierarchical URL like this: Change:...
5
by: Sam | last post by:
Does anyone know of a way to create a search page under ASP.NET 2.0? I have started out by configuring a catalog in Index Server, registering the aspx, ascx extensions in the registry to allow...
2
by: | last post by:
Apache has a look-back feature that lets it scan back down the URL if it doesn't find what it is looking for. For example: http://www.domain.com/article.php/999/12 In this above case there is no...
8
by: Roman | last post by:
I received a marketing call from a guy first showing me my website and then some other website and ranking of that other website. My questions is it worth paying to SEO corporation a $1200 -...
8
by: Bruno Rafael Moreira de Barros | last post by:
I have this framework I'm building in PHP, and it has Search Engine Friendly URLs, with site.com/controller/page/args... And on my View files, I have <?=$this->baseURL;?to print the base URL on the...
2
by: flickle1 | last post by:
Hi, I created a website in PHP www.poundsback.com and i want to know how to make Friendly URL's if you browse the website you will see that some of the urls are quite long in size. I heard...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.