1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with my redirect concept

Discussion in 'Apache' started by Michael_version_2, Jan 8, 2020.

  1. #1
    Hi,
    I'm asking for some assistance with my approach to a redirect scheme I'd like to implement. I've started hacking with the .htaccess file to some degree of success but I've read some messages here and it seems there is more than one way to skin the cat so I'd appreciate comments from those more experienced than I as to how to go about what I'm trying to accomplish.
    SEMrush
    I have a real estate site and wish to make pretty URLs of essentially a one-page site that writes itself based on query string values eg. .../index.html?property-type=house&state=ny&city=niceville... When this page loads, the filter is applied using javascript and only those listings that meet the criteria are shown.

    I'd like to pretty this up so the url appears to be /for-sale/houses/ny/niceville. (There are other criteria but I am open to leaving them on the query string instead of /for-sale/houses/ny/niceville/2beds/2baths, /for-sale/houses/ny/niceville?beds=2&baths=2).

    The part that is tricky is that there may or many not be property-type, state & city in a search so I have to figure out somehow what the url is saying when there are less than 3 criteria e.g. /for-sale/niceville, I have to figure out that niceville refers to the city and not the state or property-type. I'm starting to think that trying to do this in the .htaccess file is going to be difficult.

    I saw one idea about redirecting everything to a php page and accomplishing what I want to do there. I'm not an expert in php but figure it can't be too difficult to get it to load a list of cities so that if it sees "niceville" it can recognize it and rewrite the url to ...?city=niceville.

    Anyway, any comments would be greatly appreciated.
     
    Michael_version_2, Jan 8, 2020 IP
    SEMrush
  2. Private Loader

    Private Loader Member

    Messages:
    96
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    48
    #2
    Yes, use PHP. You prepare the PHP file to receive a string request GET or POST and then you filter the code to match what you are trying to achieve.
     
    Private Loader, Jan 8, 2020 IP
  3. Michael_version_2

    Michael_version_2 Peon

    Messages:
    7
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    3
    #3
    I have it solved. I want whatever the url is to be served by index.html (except css, js etc, plus any other html files to be handled directly) so I did RewriteRule ^.*for-sale/.*$ index.html [L] in the .htaccess. Now I can fetch http://mysite.com/for-sale/ or http://mysite.com/for-sale/houses/ny/niceville and it just fetches index.html so I can look at window.location and figure out from the url what the user actually wants served. I'm not sure if this makes any sense but maybe it helps someone. Getting my head around internal urls... I wasted way too much time on this but until the next unforeseen issue, I think I'm good. Thanks all.
     
    Michael_version_2, Jan 8, 2020 IP
    JEET likes this.
  4. JEET

    JEET Notable Member

    Messages:
    3,163
    Likes Received:
    318
    Best Answers:
    10
    Trophy Points:
    235
    #4
    @Michael_version_2

    The exact same thing is done using PHP too, with minor differences.
    Like in javascript you are looking at window.location
    In PHP, you would look into $_SERVER for QueryString.

    Redirect would be to index.php instead of to index.html

    By the way, if this real estate script is not already a php plus MySQL script, then how are you storing all those category,city etc info? Cannot be in plain javascript vars...
     
    JEET, Jan 8, 2020 IP
  5. Michael_version_2

    Michael_version_2 Peon

    Messages:
    7
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    3
    #5
    Hey Jeet. How's it going? Believe it or not I actually took a very roundabout route through using a php page with $_SERVER until I realized it was unnecessary for what I had already written in the front end since I wasn't using php for any other purpose but to get something window.location would give me.

    To answer your question, my data set is quite small on the public side of the site so I just include a javascript page with all the info. It only amounts to about 250 Kb of data at this point. Internally, the dataset is larger with properties not published and in that case the data is served by couchdb which serves json using REST calls so it is always current. When new properties are added to the public site I have to save the json to the javascript file included in index.html. Not particularly scientific but it gets the job done and is a system I've been using for years now. All the best.
     
    Michael_version_2, Jan 9, 2020 IP
    JEET likes this.
  6. JEET

    JEET Notable Member

    Messages:
    3,163
    Likes Received:
    318
    Best Answers:
    10
    Trophy Points:
    235
    #6
    You must think about a server side system. Currently, here is what is happening, per call:

    1. Person opened your site.
    Your HTML and basic stuff got downloaded.
    That 256KB file "also" got downloaded.

    2. User selected something from javascript dropboxes, city, property etc.
    A clientside request was sent to access a huge JSON file with actual property info data.
    This large file also gets downloaded first on clientside, and then javascript does its parsing work.

    3. User changed the property in dropbox.
    Again a new file got downloaded.
    and so on.

    In other words, your entire "small" dataset is getting downloaded to client's temporary files folder, each time they open your site...

    Not to mention, your entire output is in javascript, so you may or may not be losing some search engine traffic.
    For search engines, you are showing a blank page.
    I'm not a huge fan of depending on SEO for traffic, but it sometimes help.

    In any case, do think about switching to some server side system.
    Even if not MYSQL plus PHP, then flat file plus PHP at least.
     
    JEET, Jan 9, 2020 IP
  7. Michael_version_2

    Michael_version_2 Peon

    Messages:
    7
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    3
    #7
    Hey Jeet. Really appreciate your comments. Since the dataset gets loaded from a script tag I would assume it gets cached although when I load the site with caching turned off it still loads quickly. These are the numbers with caching disabled...
    40 ms Loading, 158 ms Scripting, 86 ms Rendering, 61 ms Painting, 219 ms System, 2490 ms Idle, 3055 ms Total

    Regarding SEO, my understanding is that is no longer the case. Apparently, google at least, now renders the page using javascript and you can even dynamically change the title using javascript and the page is indexed appropriately.
     
    Michael_version_2, Jan 11, 2020 IP
    JEET likes this.
  8. Michael_version_2

    Michael_version_2 Peon

    Messages:
    7
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    3
    #8
    Just to add a point to the above, that test is done with two criteria selected so it is doing an active filter in the page whose numbers I pasted above. The url for those numbers was ...for-sale/apartments/<neighborhood>/.
     
    Michael_version_2, Jan 11, 2020 IP
    JEET likes this.
  9. JEET

    JEET Notable Member

    Messages:
    3,163
    Likes Received:
    318
    Best Answers:
    10
    Trophy Points:
    235
    #9
    Don't get me wrong. I am not saying this is wrong or causing major issues. I am saying that this is not an efficient way of doing this.

    Suppose if javascript was the better way of maintaining databases,
    and someone would have told me to switch to JS from PHP,
    then I too would have hated it because I am not too good with javascript.

    I understand that you are very good with javascript and you prefer doing it this way, but all I am saying is, think about doing the same in PHP instead cause that is a much better way of handling large datasets.
    You will still be able to use your flat json files to store data. No need to learn additional SQL also.

    Anyways if this system works for you, good then, take care, good luck :) :) :)
     
    JEET, Jan 11, 2020 IP
  10. Michael_version_2

    Michael_version_2 Peon

    Messages:
    7
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    3
    #10
    Thanks for your comment, JEET. I really appreciate it. You are absolutely right that I really don't want to learn a new programming language even though perhaps I should. In the end, this works for me and as you know, the chase for perfection can be a never ending pursuit. All the best to you.
     
    Michael_version_2, Jan 11, 2020 IP
    JEET likes this.