Forum Moderators: phranque
I have run into a problem with a rewrite. I am probably missing something obvious... :(
The URI I have:
[example.com...]
What I need is this:
[example.com...]
or even better:
[example.com...]
And this is what I was advised to do (by someone from across the Atlantic):
RewriteEngine on
RewriteBase /
RewriteRule ^/search(.*) /cgi-bin/search$1
This, if put into my root .htaccess, fails to work. The URI stays the same...
Please help the dim-witted...
thank you,
M.
Do you not want it to? What are you trying to accomplish in the end -- Search engine friendly URLs? I'm asking because it's not clear what your goal is, and the solution can change drastically depending on the purpose.
The reason the URL does not appear to be changing is that your code invokes an internal rewrite, which is not visible to a browser. It is a simple file substitution, and takes place entirely within the server. But that may or may not be what you wanted. The alternative is an actual external redirect, where the server will send a message back to the client saying, "That resource has moved. Send a new request using the following new URL: http://www.example.com/new_URL"
A good way to state these problems is to say "I want to type "http://example.com/subirX/" into my browser, and I want the server to serve a response from "http://example.com/subdirY/" -- This makes it clear which URL is seen at the client end, and which URL is used inside the server.
Jim
Do you not want it to? What are you trying to accomplish in the end -- Search engine friendly URLs? I'm asking because it's not clear what your goal is, and the solution can change drastically depending on the purpose.
I'm sorry for being unclear. I would like to rewrite an URI that is returned by a site search engine. Let me restate the problem.
1. The user is presented with a page that has a search box on it. The user then types a keyword, and executes the search. This page is located at:
mydomain.com/folder/file.html
That is where the search starts from.
2. The search engine receives the query, and returns a page with results. It is that page that has an ugly URI that I want to rewrite. Specifically, the page returned is:
mydomain.com/cgi-bin/search/search.pl?p=1&lang=en&include=&exclude=&penalty=&sort=&mode=any&q=keyword
3. What I would like to do is to use .htaccess to rewrite that URI that is returned by the search engine, to this:
mydomain.com/search
or, at most,
mydomain/folder/search
. I don't know how to put it another way...
A good way to state these problems is to say "I want to type "http://example.com/subirX/" into my browser, and I want the server to serve a response from "http://example.com/subdirY/" -- This makes it clear which URL is seen at the client end, and which URL is used inside the server.
The user is presented with a long URi by a search engine, so they will never type it themselves, nor is the search results page being linked from anywhere.
I just would like to hide the mess (and reference to cgi-bin) that the search engine returns.
M.
Mod_rewrite can only act when an HTTP request is received by your server, and before any resource (page, image, script, etc.) is served. It cannot be used to modify the output of your server.
You might want to look into some of the PERL libraries and similar that can be used to submit the search request on behalf of your user, capture the output page, modify it, and then serve the modified result as a response. This may be too complex for your tastes, but it is the simplest way I can think of to modify dynamically-created page output.
Jim