Forum Moderators: phranque
I have a website with different categories. Each category contains some pages with information about that category.
At the moment i'm using a simple index.php to redirect users to the correct page:
index.php?cat=$category&page=$page.
This will redirect the user to
~/pages/$category/$page.php
However, I'd like to have the user to input:
~/pages/$category/$page.php
instead of the first option...
My knowledge of htaccess seems to be insufficient to solve this, as there are two parameters involved :)
Also, I've read in another post that Google will still use the dynamic urls (http://www.webmasterworld.com/forum92/4438.htm). Is there any way to make Google also use the second option?
Thanks in advance!
That's a 'static' URL, in the loose terminology we're using here, while
index.php?cat=$category&page=$page
is the corresponding 'dynamic' URL. The terminology is "loose" because it's not really the URL that is static or dynamic, it is the resource that the URL refers to that is either a static hard-coded page or a script which dynamically generates content based on the URL or the URL query string.
All you have to do is expand your current code to add a two-parameter rule. You'll do this by adding another pattern and back-reference to a copy of the current rewriterule, so that two-parameter static URLs will be recognized, and their parameters will be moved into the query string of the dynamic URL.
Due to limited contributor participation, we can't support "write my code for me" requests here, and prefer instead to help you learn to modify and write your own code. This approach is better aligned with our forum charter, spawns more meaningful and generally-useful discussion, and has the added benefit of leaving you (and others who read the thread later) better able to support your own future needs. So, if you want to post your best effort to solve the problem yourself, or ask very-specific questions on particular points you don't understand, then you'll find this forum quite supportive.
The resources cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com] may prove useful in this effort.
Jim
The link was an example page where i found info about the method to prevent google from "seeing" the dynamic (ie with?) url.
As for your remark: i totally agree! I'm sorry that i made it look in my previous post like i wanted to have a "cut-&-paste" solution from you... Rather, i wanted to get pointed into the correct direction, as you have done.
Using your links, I've seen into the problem a bit more carefully, and come up with the following solution:
Options +FollowSymLinks
RewriteEngine on
# Internally rewrite search engine friendly static URL to dynamic filepath and query
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?cat=$1&page=$2 [L]
# Externally redirect client requests for old dynamic URLs to equivalent new static URLs
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?cat=([^&]+)&page=([^&]+)\ HTTP/
RewriteRule ^index\.php$ [somedomain.com...] [R=301,L]
I also added a .htaccess file to my css folder:
Options +FollowSymLinks
RewriteEngine off
made the links to the css relative to the root of my server. This to make the css work together with the new .htaccess rules.
I'm not entirely sure whether the last rules for the google bots will do the trick for my domain though... For example: i'm not familiar with ^[A-Z]{3,9}\ and so don't have an accurate idea what it'll do...
Thanks again!
Cheers!
Evarest
GET /index.php?cat=$category&page=$page HTTP/1.1
So [A-Z]{3,9} matches "GET", "HEAD", "POST", "PROPFIND", etc., all capital letters, ranging from 3 to 9 characters in length, which is then followed by a space, a slash, the URL, the query string, then a space, and then ending with the requested protocol -- HTTP/1.0 or HTTP/1.1.
Concerning page-relative and server-relative links, just remember that it is the client that resolves on-page links. While the client will be aware of redirected page URLs, it will have no knowledge of internally-rewritten URLs. Thus, if the ~/pages/$category/$page.php URL is rewritten to /index.php?cat=$category&page=$page, and that page refers to a CSS file as "mycss.css", the client will think that the CSS file is located at ~/pages/$category/mycss.css
So, you can either use the server-relative URL format (as you did), or you can rewrite the 'common' CSS, external JS, and image requests to the correct filepath as well.
Jim