Pentium10
Pentium10

Reputation: 207912

How to include a dash(#) in a htaccess rewrite rule?

As you know the dash introduces a comment

how can I make this valid?

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+)\.php$ /#$1 [R=301,NC]

Upvotes: 1

Views: 674

Answers (3)

Enrico Carlesso
Enrico Carlesso

Reputation: 6934

You can't manager data after # by apache. Even facebook handles redirection for data after # by javascript.

If I'm wrong, please someone correct me, some years ago this problem drives me crazy.

Upvotes: 1

John Feminella
John Feminella

Reputation: 311526

Replace the # with \%23, and that should do the trick, or use the [NE]/noescape flag.

Upvotes: 0

Gumbo
Gumbo

Reputation: 655269

Use the NE flag:

RewriteRule ^(.+)\.php$ /#$1 [R=301,NE]

By the way: The # is only the start of a comment if used at the start of a line:

Lines that begin with the hash character "#" are considered comments, and are ignored. Comments may not be included on a line after a configuration directive.

Upvotes: 1

Related Questions