iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Search Engine Optimization Forum SEO is much easier with help from peers and experts! The WebProWorld SEO forum is for the discussion and exploration of various search engine optimization topics. Any non (engine) specific SEO or SEM topics should go here.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-26-2008, 04:50 AM
son son is offline
WebProWorld New Member
 
Join Date: May 2008
Posts: 20
son RepRank 0
Default Search engine friendly urls

Making urls search-engine-friendly I put the following entry in .htacess:
RewriteEngine On
RewriteRule ^/services/$1 /services.php?id=$1

I thought it would show me 'services.php?id=3' if I entered 'services/3' for example. Instead it says 'Page cannot be found'. The host confirmed there are no restriction with regard to rewrite engines, so I really do not understand what is going wrong. The entry is simillar to the ones I found as examples online. I would appreciate any help with this...

Son
Reply With Quote
  #2 (permalink)  
Old 11-26-2008, 10:16 AM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,648
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: Search engine friendly urls

Try:

RewriteRule ^/services/(.*)$ /services.php?id=$1 [L]

In the first portion of the rule, the question mark has a different meaning than it does in the second portion. In the first portion, it is used to denote the end of the URI. In the second portion, it denotes a variable. The text you want to store in a variable should be enclosed in parenthesis. In this case, I used .*, which is a regular expression. The dot matches any single character, while the asterisk matches any number of characters. If the only valid character is a single digit number, the following rule should work instead:

RewriteRule ^/services/[1-9]$ /services.php?id=$1 [L]

If the rule should work on any number, from one to four digits, you could use this:

RewriteRule ^/services/[0-9]{1,4}$ /services.php?id=$1 [L]
__________________
The best way to learn anything, is to question everything.
Reply With Quote
  #3 (permalink)  
Old 11-26-2008, 05:32 PM
WebProWorld Pro
 
Join Date: Dec 2007
Location: Pullman, WA (from CA)
Posts: 138
a53mp RepRank 2
Default Re: Search engine friendly urls

Quote:
Originally Posted by wige View Post
Try:

RewriteRule ^/services/(.*)$ /services.php?id=$1 [L]

In the first portion of the rule, the question mark has a different meaning than it does in the second portion. In the first portion, it is used to denote the end of the URI. In the second portion, it denotes a variable. The text you want to store in a variable should be enclosed in parenthesis. In this case, I used .*, which is a regular expression. The dot matches any single character, while the asterisk matches any number of characters. If the only valid character is a single digit number, the following rule should work instead:

RewriteRule ^/services/[1-9]$ /services.php?id=$1 [L]

If the rule should work on any number, from one to four digits, you could use this:

RewriteRule ^/services/[0-9]{1,4}$ /services.php?id=$1 [L]
if you want to allow numbers and letters use

RewriteRule ^/services/[a-zA-Z0-9]$ /service
if you want to add other characters like a dash...

RewriteRule ^/services/[a-zA-Z0-9.-]$ /service
Reply With Quote
  #4 (permalink)  
Old 11-26-2008, 06:13 PM
son son is offline
WebProWorld New Member
 
Join Date: May 2008
Posts: 20
son RepRank 0
Default Re: Search engine friendly urls

I tried it and it still does not do it. My entry is now:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/services/[a-zA-Z0-9.-]$ /services.php?id=$1 [L]

The id is actually a word or a combination of two words combined with a minus sign (if that is where my problem lies)... I do not get why this is going nowhere. Always page not found...

Any ideas?

Son
Reply With Quote
  #5 (permalink)  
Old 11-26-2008, 06:23 PM
WebProWorld Pro
 
Join Date: Dec 2007
Location: Pullman, WA (from CA)
Posts: 138
a53mp RepRank 2
Default Re: Search engine friendly urls

the ".-" tells it to allow the minus sign

Who is your host? It might not allow mod_rewrite
Reply With Quote
  #6 (permalink)  
Old 11-26-2008, 06:36 PM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,648
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: Search engine friendly urls

Try:

RewriteRule ^/services/([a-zA-Z0-9\-]*)$ /services.php?id=$1 [L]

The dash is a reserved character and usually needs to be escaped with a backslash.

You also still need to have the parentheses. That is how mod_rewrite knows which part of the original string to use to replace the $1.

Also, you need to tell mod_rewrite how many characters to match. The brackets will only match a single character that matches the range of possible characters listed. Adding the asterisk after the closing bracket tells it to match as many characters as there are.
__________________
The best way to learn anything, is to question everything.

Last edited by wige; 11-26-2008 at 06:39 PM.
Reply With Quote
  #7 (permalink)  
Old 11-26-2008, 06:38 PM
son son is offline
WebProWorld New Member
 
Join Date: May 2008
Posts: 20
son RepRank 0
Default Re: Search engine friendly urls

Checked already with Host, but they say there is no restriction on mod_rewrite and they cannot provide assistance with programming etc.

I really do not get this, the real URL could be:
http://www.domain.com/services.php?id=consultancy
so the given entry as:
RewriteRule ^/services/[a-zA-Z0-9.-]$ /services.php?id=$1 [L]

should really take care of it. It does not. I also tried on different server (with different host) and on local machine. Not any better... Why could that be?

Son
Reply With Quote
Reply

  WebProWorld > Search Engines > Search Engine Optimization Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which URL is Search Engine Friendly? Ozzman Search Engine Optimization Forum 2 02-08-2008 11:01 AM
Non Search Engine Friendly sunbedkid Link Exchange 2 05-26-2005 10:31 PM
Search Engine friendly CMS grasko Web Programming Discussion Forum 29 10-20-2004 08:56 PM
Search Engine Friendly(SEF) URLs mySunSite Search Engine Optimization Forum 2 10-07-2004 09:23 AM
Multiple Search Engine URLs on Home Page mgtman Search Engine Optimization Forum 1 08-12-2004 06:39 PM


All times are GMT -4. The time now is 04:42 AM.



Search Engine Optimization by vBSEO 3.3.0