0

I'm moving an old site into an /archive sub directory of a the new website. The site is all HTML has lots of fully qualified URL to when it wasn't in the archive folder (e.g. (http://domain.com/pictures/home.html). This is fine as I have rewritten any unfound files to the /archive directory.

The problem is... a lot of these fully qualified URLs have # in the filename e.g. http://domain.com/pictures/category#001.html. These are then linked to as http://domain.com/pictures/category%23001.html. When the rewrite is applied to these URLs, the server doesn't find the file giving a 404 error, with the path truncated at the %23 (e.g. '/archive/pictures/category was not found on this server.')

I've tried using the [B] flag, which still gives the 404 error but the file path it gives does exist (e.g '/archive/pictures/category#001.html was not found on this server.').

If I navigate directly to the file in the archive directory using the %23 in the URL(e.g. http://domain.com/archive/pictures/category%23001.html) then the everything works fine. The only issue is when adding the /archive directory through the RewriteRule

The rule is simply this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /archive/$1 [B,L,QSA]

I've also tried replacing the rule with this:

RewriteRule (.*) /archive/%{REQUEST_URI} [B,L,QSA]

But it has the same issue.

Thanks for reading this far!

2 Answers 2

1

You need to use NE flag here (which avoids escaping):

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ((?!archive/).*) /archive/$1 [NE,L,NC]
Sign up to request clarification or add additional context in comments.

2 Comments

Using the NE flag still didn't work for me unfortunately. The only way I could achieve getting the file was to redirect to it
Did you also try: [NE,L,NC,B]?
0

In the end the only way I could get the server to go to the file was to redirect to it, instead of rewriting the URL, using the following code (R=302 flag added).

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /archive/$1 [R=302,B,L,QSA]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.