Forum Moderators: coopster
This is a sample URL that I am trying to rewrite:
[mydomain.com...]
----------------------------
I would like to rewrite the URL with the following or with anything.html(This is the URL I would like displayed on the URL bar.):
[mydomain.com...]
--------------------------------
This is what I wrote last on my .htaccess file(with no success):
RewriteEngine on
RewriteBase /
RewriteRule ^catalog\/default\.php\/cPath/\21$ catalog\/pcsoft\.html
Do not escape any characters in the target URL. There is also no need to escape "/" characters.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^catalog/default\.php/cPath/21$ /catalog/pcsoft.html [R=301,L]
The [R] flag forces external redirection so that the client browser address bar is updated - The browser will then re-issue the request with the updated URL. You can use R=301 for a permanent redirect, or R=302 for a temporary redirect. The [L] flag tells mod_rewrite that it can stop processing rewrites for this request if the current rule matches and is applied.
This Introduction to mod_rewrite [webmasterworld.com] post and the Apache and regular-expressions documentation cited within it might come in handy.
Just in case... Understand that URLs are rewritten after the client browser makes a request and before the server returns any document. Therefore, you can rewrite URLs that are requested by the browser to a different URL, but you can't use mod_rewrite to change the output of your scripts.
HTH,
Jim
Thanks for your help! I tried the lines of code that you gave me:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^catalog/default\.php/cPath/21$ /catalog/pcsoft.html [R=301,L]
The html url is being displayed on the address bar. However, I am getting a 404 error with the following message:
"The requested URL /shop/pcsoft.html was not found on this server.Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."
I am going to contact the hosting company I am using. Perhaps, although they said they support mod_rewrite, may be they have not configured it accordingly. Thanks again JD!
Wolverine
If you tested by requesting yourdomain.com/catalog/default.php file, the error message shows that the rewrite did, in fact, occur. However, yourdomain.com/catalog/pcsoft.htm does not exist, and there is a problem with your custom error document setup.
As written, the rewrite rule will take an incoming request for the URL yourdomain.com/catalog/default.php and redirect to serve the /catalog/pcsoft.htm file instead.
Jim
I guess I am still confused in regards to mod_rewrite.
I am only trying to rewrite the URL of a dynamic page. If the rewrite rule is attemptimg to serve /catalog/pcsoft.html and such HTML does not exist then I will continue to get 404's. The only reason I am trying to rewrite the URL is so that GBOT can find at least the dynamic main category pages. I just went to sitepoint to read a couple of articles and it is still a mystery to me why this URL rewrite is not working because their sample look just like what I am using now. I sent an email to the hosting company I am using explaining what I am trying to accomplish and all I got was "Your html page is missing that is why you'r getting a 404".
I am going to continue trying until I get it to work!
I do appreciate your help and tips! Thanks!
Wolverine
It is important to understand what "rewrite" means; which "direction" it goes, and when it happens. You may actually be reversing the "from" and "to" URLs in the code you posted.
RewriteRule ^a\.html$ /b.html [L]
Takes a client browser request for "a.html" and serves the file "b.html".
HTH,
Jim