Forum Moderators: phranque

Message Too Old, No Replies

htaccess redirect dynamic to totally different static URL

I want to redirect, not rewrite ...

         

loic

10:43 am on Sep 29, 2009 (gmt 0)

10+ Year Member



Sorry for noob question.
I'm trying to redirect

[mydomain.net...]
to
[mydomain.net...]

on the .htaccess file located on my root I have :


Options +FollowSymLinks
RewriteCond %{query_string} ^cPath=24_31
RewriteRule ^shop/index\.php$ http://mydomain.net/shop/mode/bijoux.html? [R=301,L]

but it just doesn't work.

jd01

12:24 pm on Sep 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Options +FollowSymLinks
RewriteCond %{query_string} ^cPath=24_31
RewriteRule ^shop/index\.php$ [mydomain.net...] [R=301,L]

Hi loic & Welcome to WebmasterWorld!

There are two things I'm seeing:
1.) If this if your entire file, you are missing the ever important RewriteEngine on

2.) QUERY_STRING should be capitalized.

Other than that it looks good, so the version I would tell you to try is:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^cPath=24_31
RewriteRule ^shop/index\.php$ http://example.com/shop/mode/bijoux.html? [R=301,L]

You could 'end anchor' your QUERY_STRING too:
^cPath=24_31$ but that's minor and should not effect the rule working.

Let us know how that goes and if it doesn't work, please provide some specific details re 'doesn't work' so we can trouble-shoot it a bit deeper.

jdMorgan

1:38 pm on Sep 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, be sure to completely-flush (delete) your browser cache after changing any server-side code. Otherwise, your browser will show you previously-cached pages and server responses instead of sending a new request to your server, and thus confuse your test results...

Jim

loic

7:53 pm on Sep 29, 2009 (gmt 0)

10+ Year Member



Thank you both for your welcome and quick advices.
I took me a while to test, I wanted to make sure I fully test it all before coming back to you.
well it doesn't work.
I now have the code provided by jd01.
It doesn't redirect me, but I don't have an error either. it is just leading me to [mydomaine.com...]
(and the url doesn't change...)

I've investigated and turns out there is another .htaccess WITHIN the /shop/ directory and I guess it might confict.

(this is a magento install)


############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

############################################
## rewrite everything else to index.php
RewriteRule .* index.php [L]


Is this conficting you think ?

Caterham

8:57 pm on Sep 29, 2009 (gmt 0)

10+ Year Member



I've investigated and turns out there is another .htaccess WITHIN the /shop/ directory and I guess it might confict.

The merging will override your /path/document/root/.htaccess, yes. Either you move your rule to the subdir (by adjusting the rule-pattern accordingly ( ^index\.php$ ) or your other rule to the document root (with path adjustments, of course).

If you don't use symbolic links within your documentroot and its subdirs at all, you could drop the third condition since checking for such would be useless in those cases.

loic

11:10 pm on Sep 29, 2009 (gmt 0)

10+ Year Member



It worked !
Thank you thank you.

for the record, my testings were confused like jdMorgan said but NOT because of cache. It's because I was on a MAC !

using dreamweaver, updating .htaccess and uploading it was crashing my site with 500 errors.
Only when I SSH'ed I culd see a ^M causing the file to be only 1 line ....
Now I know that the ^M is actually a MAC carriage return.
Anyone knew that ?

Thanks again

jdMorgan

11:39 pm on Sep 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use only a plain-text editor to create and edit .htaccess files, and if you can, set it to use *nix line-enders (LF-only). Then upload with SFTP (or plain FTP if necessary).

Jim