Forum Moderators: phranque
This is the type of URL in question:
http://www.example.com/view.php?company_id=58&auth_sess=60fiv6c7u67gele5tn6b27ngr7&ref=69245dccbb2084495b04eaa47
Company ID numbers are fixed for each company (so company ID might be ID=2, company 3=ID3..and so on.Doesnt change)
Session string of course will change!
The user does not need to be logged in. (but can view the same thing if they are)
Now, the site is (currently) based on a heavily customised Php Mysql script.It is very over complex and not very well coded so we are currently building a much faster and more SEO friendly site from the ground up.
However its what we have for at least the next few months until the new site is done.
Hence the need for all the re writes.
These are the current top lines of the .htaccess
The remaining lines below (not shown) are for individual file names and not patterns.
RewriteEngine On
RewriteBase /
RewriteRule ^adverts/([^/]*)-.*.html /view.php?job_id=$1 [L]
RewriteRule ^company/([^/]*)-.*.html /view.php?company_id=$1 [L]
RewriteRule ^jobs/(.*).php /$1.php [L]
RewriteRule ^company/(.*).php /$1.php [L]
Is there any guru out there who can tell me if this re write is possible please?
THANKS
[edited by: jdMorgan at 5:01 pm (utc) on Aug. 12, 2007]
[edit reason] example.com [/edit]
Sorry about that. I thought I had posted it!
ok. so here goes with a couple of examples.
I currently have a URl that I get at the moment when a companies information page is viewed...
http://www.example.com/view.php?company_id=48&auth_sess=ron6ii35of23b9bqhc2t5f42m5&ref=75cf6ca1c103a2ed10d810147
I would like this URL to be re written to
http://www.example.com/info/company-48.html
Another one is when the user logs out, they click logout and get this ridiculous long URl!
http://www.example.com/index.php?language=english&empl=1&auth_sess=ron6ii35of23b9bqhc2t5f42m5&ref=0859a1754c0cd8a05860fc0d3
If its possible I would like to rewrite that back to
http://www.example.com/employer-home.html
because thats the page they stay on when they log out anyway! (note that that URL has a english&empl in it)
The last one is (this is for site users and the 'english&empl' is missing from the string
http://www.example.com/index.php?language=english&auth_sess=em5q6euiata9ba5djc8npkin05&ref=3abb8f13a49b5630df9f6d359
and to rewrite this to
http://www.example.com/
I cant get my head around getting the session string junked but so that it works at the correct time! All other URLs on the site are re written and its only these pesky problem ones.
I will post my attempt at re writing these shortly and if anyone can correct I would be very grateful!
thanks
[edited by: jdMorgan at 5:02 pm (utc) on Aug. 12, 2007]
[edit reason] example.com [/edit]
I currently have a URl that I get at the moment when a companies information page is viewed...http://www.example.com/view.php?company_id=48&auth_sess=ron6ii35of23b9bqhc2t5f42m5&ref=75cf6ca1c103a2ed10d810147
I would like this URL to be re written to
http://www.example.com/info/company-48.html
OK, one more question. Please read very carefully, as getting this right is absolutely critical.
Are the following two statements true?
http://www.example.com/info/company-48.html is the link that currently appears on your page
-and-
/view.php?company_id=48&auth_sess=ron6ii35of23b9bqhc2t5f42m5&ref=75cf6ca1c103a2ed10d810147 is the local URL-path and query string for the script that handles the request for that link.
The reason I am asking is that in this case, the former needs to be rewritten to the latter, and not the reverse. It's critical to get this right; If the above statements are not true, then problem has not yet been correctly defined.
Note that only your script controls the URLs displayed as links on your pages, so if the displayed link URLs are not currently correct, then mod_rewrite is not the solution.
Jim
OK, one more question. Please read very carefully, as getting this right is absolutely critical.
Are the following two statements true?
http://www.example.com/info/company-48.html is the link that currently appears on your page
-and-
/view.php?company_id=48&auth_sess=ron6ii35of23b9bqhc2t5f42m5&ref=75cf6ca1c103a2ed10d810147 is the local URL-path and query string for the script that handles the request for that link.
The reason I am asking is that in this case, the former needs to be rewritten to the latter, and not the reverse. It's critical to get this right; If the above statements are not true, then problem has not yet been correctly defined.
Note that only your script controls the URLs displayed as links on your pages, so if the displayed link URLs are not currently correct, then mod_rewrite is not the solution.
ok JD.
I have now got my head around what your asking!
I will try and explain with more clarity so please bear with me on this!
http://www.example.com/info/company-48.html is the link that currently appears on your page
This statement is not true, at present the URL that is showing in the browser window is:
http://www.example.com/view.php?company_id=48&auth_sess=ron6ii35of23b9bqhc2t5f42m5&ref=75cf6ca1c103a2ed10d810147
for the second question:
/view.php?company_id=48&auth_sess=ron6ii35of23b9bqhc2t5f42m5&ref=75cf6ca1c103a2ed10d810147 is the local URL-path and query string for the script that handles the request for that link.
This statement is totally true, the file view.php is located in the root directory and the long string is the query string for the script.
/ I was hoping it is possible to hide the long session ID and rewrite the URL to something more meaningful to search engines!
Like http://www.example.com/info/company-48.html
Not sure if it is possible tho because the session contains so many random characters I have no idea of how to go about it!?
thanks for your time
Well, the problem is that a rewrite cannot do that. The link that appears on your page is what the search engines (and everybody else) sees. The link on the page defines the URL.
You can change the URL on the page to something 'friendly' by modifying the script that generates the page. Then when a client (browser or SE) requests that friendly URL, mod_rewrite can detect it and convert it back into the original 'unfriendly' server-internal URL-path needed to invoke your script to produce the next page.
mod_rewrite acts after a URL is requested from your server, and before any content-handlers are invoked. Therefore, you can view it as a requested-URL translator. But it does not modify the links on your pages; Only your script(s) can do that.
There is one caveat when modifying the script(s): The new, friendly URL must contain all of the information needed to produce a correct and corresponding 'unfriendly' internal URL-path when mod_rewrite acts on the incoming friendly URL request -- Obviously, mod_rewrite cannot create information out of thin air, although it can re-arrange, re-format, and transliterate existing information...
Jim
[edited by: jdMorgan at 2:08 pm (utc) on Aug. 17, 2007]
Crucial to that understanding was that a URL for a page is defined by what was in the link that I followed. If content was then returned with "200 OK" then that was the URL for the page right there.
However, internally, the server could be "translating" that URL into an internal filepath that was different to that suggested by the URL that I was looking at.
Normally you would expect that www.domain.com/some.folder/some.file.html was simply fetching data from /user.name/pub/html/site.name/some.folder/some.file.html on the server.
However with a rewrite it could also quite easily be coming from /user.name/pub/html/site.name/the.script.php?parameter1=some.folder¶meter2=some.file and the user would never know. With an internal rewrite the user continues to see the URL that they requested.
In contrast, a redirect forces the browser to request a new URL. It is external. You use that to redirect named index file filename requests back to "/" in order to avoid Duplicate Content issues. You also use it for people attempting to access your site using the dynamic URLs. They get redirected back to the static-looking format too. You also use it to redirect from non-www to www; another Duplicate Content fix. The redirect must be a 301 redirect.
You must use the static-looking URLs in the content of all of your pages as that is what you want to be indexed.