Forum Moderators: phranque

Message Too Old, No Replies

match trailing slash

         

orsopoeta

6:19 pm on Dec 17, 2009 (gmt 0)

10+ Year Member



hi all

i have to a simple Redirect 301
but i don't be able to match the trailing slash!

:-(

[domain1...]
i have to redirect to
[domain2...]

my rewriting

RewriteRule %{HTTP_HOST} ^domain1$
RewriteRule ^categoria/soppalchi-9/?$ [domain2...] [R=301,L]

but not works :o(
i try with various regexp

soppalchi-9/?
soppalchi-9(/).
soppalchi-9\/?
soppalchi-9//?

without success :o(

if a remove the last slash in url (categoria/soppalchi-9/) it works!

can anyone help me?

many thanks

Roberto

jdMorgan

8:33 pm on Dec 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just using a literal slash should be sufficient:

RewriteRule %{HTTP_HOST} ^domain1$
RewriteRule ^categoria/soppalchi-[b]9/$[/b] http://domain2/categoria/soppalchi-9/ [R=301,L]

However, be sure that this new rule precedes any other rules which may also match that URL, be sure that no other modules' directives are interfering (such as mod Alias "Redirect" or "RedirecMatch" directives), disable MultiViews (also called "content-negotiation") using the Apache core "Options" directive unless your site requires it, disable AcceptPathInfo if you're on Apache 2.x unless your site requires it, and be sure to completely flush (delete) your browser cache after changing any server-side code.

Jim

orsopoeta

9:50 am on Dec 18, 2009 (gmt 0)

10+ Year Member



hi jim

thanks for your reply.
you're right: i'm another RewriteRule that match the regexp.

if i write:

RewriteCond %{HTTP_HOST} ^domain1$
RewriteRule ^categoria/soppalchi-9/?$* [domain2...]
RewriteRule ^categoria\/(.*)-([0-9]+)/ catalogo/index.cfm?gr=$2

don't match.. :o(

if i invert the rules

RewriteRule ^categoria\/(.*)-([0-9]+)/ catalogo/index.cfm?gr=$2
RewriteCond %{HTTP_HOST} ^domain1$
RewriteRule ^categoria/soppalchi-9/?$* [domain2...]

the webpage has a redirect loop :o(

any idea?

many thanks

Rob

jdMorgan

7:14 pm on Dec 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I made clear above that your redirect should have an [R=301,L] on it, and the rule order is critical.

You also need to investigate the other two settings I mentioned. I can't help you if you don't take the suggested actions.

Your internal rewrite rule pattern needs an end-anchor and should have an [L] flag on it. And further, it may need a RewriteCond to qualify it by checking for HTTP_HOST = domain2. I can't be sure about this latter point, because I don't know if both domains are co-hosted in this same filespace.

Jim