.htaccess for Friendly URLs... PLEASE HELP!

Hello everyone,

I am trying to rewrite my urls for better SEO reasons.
The script that i am using has a config.php file that I can set the Friendly URLs to “TRUE” and it actually does the trick for me but not the way I like it.

Currently the original url:
h t t p : / / w w w . m y s i t e . com/?cityid=-1&lang=en

is translated to:
h t t p : / / w w w . m y s i t e . com/-1_newyork/

I would like to modify this to only show the city name without the cityid. e.g.:
h t t p : / / w w w . m y s i t e . com/newyork/

Here is a copy of my .htaccess file

RewriteEngine On                                                                                                                             


# Show ad                                                                                                                                     

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/posts/([0-9]+)([-_][^/]*)?/([0-9]+)([-_][^/]*)?/([0-9]+)([-_][^/]*)?\\.html      /index.php?view=showad&adid=$7&cityid=$1 [QSA]


# Ads                                                                                                                                         

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/posts/([0-9]+)([-_][^/]*)?/([0-9]+)([-_][^/]*)?/page([0-9]*)\\.html         /index.php?view=ads&catid=$3&subcatid=$5&cityid=$1&page=$7 [QSA]

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/posts/([0-9]+)([-_][^/]*)?/([0-9]+)([-_][^/]*)?               /index.php?view=ads&catid=$3&subcatid=$5&cityid=$1 [QSA]


# Ads by cat                                                                                                                                 

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/posts/([0-9]+)([-_][^/]*)?                        /index.php?view=ads&catid=$3&cityid=$1 [QSA]


# Show event                                                                                                                                 

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/events(/(([0-9]+)-([0-9]+)-([0-9]+)))?/([0-9]+)([-_][^/]*)?\\.html         /index.php?view=showevent&date=$4&adid=$8&cityid=$1 [QSA]


# Events on date                                                                                                                             

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/events/(([0-9]+)-([0-9]+)-([0-9]+))/page([0-9]*)\\.html            /index.php?view=events&date=$3&cityid=$1&page=$7 [QSA]

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/events/(([0-9]+)-([0-9]+)-([0-9]+))                     /index.php?view=events&date=$3&cityid=$1 [QSA]

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/events                              /index.php?view=events&cityid=$1 [QSA]


# Show image                                                                                                                                 

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/images/([^/]+)/([0-9]+)([-_][^/]*)?\\.html                  /index.php?view=showimg&posterenc=$3&imgid=$4&cityid=$1 [QSA]


# Images by user, paged                                                                                                                       

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/images/([^/]+)/page([0-9]+)\\.html                     /index.php?view=imgs&posterenc=$3&cityid=$1&page=$4 [QSA]


# Top Images, paged                                                                                                                           

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/images/page([0-9]+)\\.html                        /index.php?view=imgs&cityid=$1&page=$3 [QSA]


# Images by user                                                                                                                             

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/images/([^/]+)                           /index.php?view=imgs&posterenc=$3&cityid=$1 [QSA]


# Top Images                                                                                                                                 

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/images                              /index.php?view=imgs&cityid=$1 [QSA]


# Quick ad/event/image                                                                                                                       

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/showpost/([0-9]+)([-_][^/]*)?\\.html                     /index.php?view=showad&adid=$3&cityid=$1 [QSA]

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/showevent/([0-9]+)([-_][^/]*)?\\.html                     /index.php?view=showevent&adid=$3&cityid=$1 [QSA]

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?/showimage/([0-9]+)([-_][^/]*)?\\.html                     /index.php?view=showimg&imgid=$3&cityid=$1 [QSA]


# City/Region                                                                                                                                 

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?                                 /index.php?view=main&cityid=$1 [QSA]

RewriteRule ^([-]?[0-9]+)([-_][^/]*)?                                 /index.php?view=main&cityid=$1 [QSA]

Any help would be really appreciated.


First, Welcome to SitePoint’s Apache forum!

Now, because you are using a “canned program,” I would recommend that you abandon your pursuit of a different URI:

  1. Your CMS is looking for the digit to pull the record with that ID.

  2. If you redirect from the CMS’s URI, you need to LOOP back to the CMS’s version for it to pull your record (looping is possible but only with great care - example in my signature’s tutorial).

  3. You really need to alter the way that your CMS creates and uses its links, i.e., instead of using the id of the record, it could look for the subject/title (another, UNIQUE field - I do this for http://wilderness-wally.com).

What you need most of all is a better understanding of mod_rewrite and, based on years of experience with member questions, my signature’s tutorial Article should help.