Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite Help needed : Different FIle, same regex

         

zeeshanhashmi

6:45 pm on Mar 28, 2010 (gmt 0)

10+ Year Member



Hi !

I am stuck at a situation, and have been trying hard, but nothing worked.

Let see if some on can help me here ASAP.

Ok, there is the scene.

I have a site, and I want the urls to be SEO friendly. There are 3 scripts, like

show_location.php
show_bank.php
show_br.php

The problem is that, in all these, the inputs are all text and like each other.

so if I have :

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([-a-zA-Z-0-9.,+'()]+)$ show_br.php?branch=$1 [L]

RewriteRule ^([-a-zA-Z-0-9.,+'()]+)$ show_bank.php?bank=$1 [L]

RewriteRule ^([-a-zA-Z-0-9.,+'()]+)$ show_location.php?location=$1 [L]


its not working.
Please support me with this !

Thanks
Zeeshan

g1smd

7:14 pm on Mar 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The first rule will always match all requests.

You need to design your URLs, URLs you publish to the web in your links, so that there is something different about each one, even if it is just a 'prefix' (like
/word/
or
word-
or even a single letter) of some sort.

With that in place, the patterns for the rules will be much easier to design. You'll also not inadvertently match something you shouldn't. You can then also dispense with the very inefficient -f and -d filesystem checks.

jdMorgan

7:33 pm on Mar 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Alternately, combine the three scripts and let the combined script figure out what to do with the requests that are rewritten to it.

Jim

zeeshanhashmi

3:50 am on Mar 29, 2010 (gmt 0)

10+ Year Member



Thanks a lot for your replies, both the suggestions are really good.

I have already thought of the Suggestion one, using a prefix word like, /branch/ OR branch-

but can you please guide me how to implement that prefix thing in .htaccess file ? I am not an expert of regex, so can you please give me a sample code of .htaccess file for the above scenario ?

g1smd

4:25 am on Mar 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The pattern would be something like
^word-([a-z0-9-]+)$
allowing letters and numbers and the hyphen in the URL. Adjust to suit.

zeeshanhashmi

4:52 am on Mar 29, 2010 (gmt 0)

10+ Year Member



Well ! Thanks a lot !

So for any word I can replace it like this :

^word-([a-z0-9-]+)$
for branch-branch-name

^word/([a-z0-9-]+)$
for branch/branch-name

^word.([a-z0-9-]+)$
for branch.branch-name

Am i right ?

Moreover, can you tell me if I use / then I will have to use the full path to the resources (images / css etc) RIGHT ?

g1smd

9:17 am on Mar 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, that should work, and your rules can be very efficient because they will only start with three different words: one for each type of page.

You will need to use the full
/path/to/the/file
for images, CSS and Javascipt, but that is always a good idea anyway.

jdMorgan

11:36 am on Mar 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just for clarification, when a URL to be rewritten has one or more "virtual directory path-parts" added to it for keyword-in-URL, search-engine-friendly parameter-passing, or other purposes, then page-relative included-object linking cannot be used*, and either server-relative URL-paths or full canonical URLs should be specified.

This is because the client (e.g. browser) resolves relative links based upon the domain and "directory-level" that it used to fetch the current page -- the URL currently showing in its address bar.

So link to your included objects using <img src="/images/logo.gif"> or <img src="http://www.example.com/images/logo.gif">, and not <img src=="images/logo.gif">.

* Actually, you *can* use page-relative links, but this requires additional rewrite rules to remove the unneeded "directory levels" from requested included-object URLs, and results in images with more than one valid URL -- duplicate content. This may not be a concern if you are not seeking to rank your images in image search, but it does require additional rules -- and what if you later change your mind about ranking in image search? And actually, the biggest practical concern is that the multiple URLs for each included image/JavaScript file, and CSS file will greatly reduce the benefits of client-side caching, and therefore increase the load on your server (browsers cache objects based on each object's URL).

Jim