473,788 Members | 2,848 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1600
Message-ID: <r4************ *************** *****@4ax.comfr om 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_FILENA ME} !-f
RewriteCond %{SCRIPT_FILENA ME} !-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************ **********@h54g 2000cwb.googleg roups.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
3425
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 converting a site of mine to PHP-Nuke, but if the individual modules aren't picked up in search engines I'm not going to do it. Thanks phpKid
0
4156
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 developed with PHP, you are not supposed to doubt that. As a proof that PHP pages could be crawled and indexed, refer this Google search
0
1207
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 www.domain.com/1234.html. How can this be done via code?
4
1957
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: /mysite/default.aspx?MenuID=contactus To: /mysite/ContactUs.aspx? The problem I'm having is that its really slowed things up by at least 0.5 seconds to 1 second longer just to pull up a light weight static page. The
5
2069
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 them to be indexed and built the catalog as per KB article, but I've run into an interesting problem. When you publish a website from Whidbey, it precompiles everything and strips out the searchable details of the page (metadata, html, etc)...
2
1382
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 directory or file called 12, so it looks at 999. There is no directory or file called 999 so Apache looks down the URL and sees article.php, which does exist, and calls up that script. Apache also has a global variable called $PATH_INFO that is...
8
2143
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 - $3000 setup fee and then $150 monthly to get your website search optimized ? I used the domaintools.com and it seems like my website had higher SEO rating and tag relevance than the example site he was showing me. I did not pay attention to search...
8
2123
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 links (eg. <a href='<?=$this->baseURL;?>/controller/page/args'>Go somewhere</ a>. But on the CSS / JS files, how will I do it? I wonder, because on the View files, I can do <?=$this->baseURL;?>/css/site.css, and it will work. But images on the...
2
2289
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 already you can use .htaccess
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10364
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.