jchwebdev
jchwebdev

Reputation: 5450

Redirecting a URL With # character, possible?

I think I may have painted myself int a corner. I used to have a contact page with a standard permalink /contact/.

I changed to a popup contactform accessible from every page with the anchor tag #maincontactform.

I can create links works fine.

But... how do I redirect old backlinks which use /contact to the new format?

You can't do a MOD Rewrite like this:

RewriteRule /contact #maincontactform [R=301,L]

This seems to expand to /%23maincontactform

Any suggestions?

TIA

Upvotes: 0

Views: 65

Answers (2)

Sumurai8
Sumurai8

Reputation: 20737

mod_rewrite will automatically escape special characters into their hex-form. If you don't want this, you have to explicitly tell it to not do that with the NE flag. Besides that, remember that in per-directory-context, such as a .htaccess file, the part that you match with your regex doesn't begin with a slash. http://example.com/contact should therefore be matched with ^contact/?$.

RewriteRule ^contact/?$ #maincontactform [R=301,NE,L]

See the documentation for mod_rewrite and the NE flag especially

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798546

The NE flag will prevent mod_rewrite from escaping the hash.

RewriteRule /contact #maincontactform [R=301,NE,L]

Upvotes: 0

Related Questions