Forum Moderators: phranque

Message Too Old, No Replies

Rewrite weirdness after moving test servers

         

ukgimp

9:38 am on Oct 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have on a number of occasions had to reinstall windows and I have had no problem moving files and data from the backup onto the new install. Copy and paste and it work. Well I have encountered some weirdness, well it is weird to me.

The htaccess is read and sort of works.

Imaging I have this url being linked to

[localhost...]

but it seems to redirects to this one

[localhost...]

Now if I turn the rewrite engine off it I just get a 404.

Here is the rewrite rule

rewriteEngine on
rewritebase /
rewriteRule files\/([0-9]+)\.php http:\/\/localhost\/directory\/files\/?c=$1 [L]

Any pointers as to why this might do this when it has worked on numerous times before.

Cheers

ukgimp

11:07 am on Oct 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



After much trying it seems that removeing the [L] diretive allows it to work.

Why would there be that change, i was under the impression that the [L] meant that no other rules were read past that point?

So any ideas what is going on

cheers

jdMorgan

2:09 pm on Oct 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have several syntax errors in that code.

Either of the following code fragments is valid. Use the first if you want an external redirect. Use the second if you want an internal rewrite.


RewriteEngine on
RewriteBase /
RewriteRule files/([0-9]+)\.php http://localhost/directory/files/?c=$1 [R=301,L]

RewriteEngine on
RewriteBase /
RewriteRule files/([0-9]+)\.php /directory/files/?c=$1 [L]

There is no need to escape the "/" characters in the RewriteRule pattern, as these are not reserved characters in mod_rewrite. There is no need to escape any character in the RewriteRule substitution, as it is treated only as a string except for back-reference variable names.

For an external redirect, the method (http:) and domain (//localhost) are required. For an internal rewrite, they should not be used. An external redirect sends a redirect response to the browser, requiring it to re-request the page at the new URL, and making this new URL visible in the browser address bar. An internal rewrite simply serves the contents at the substitute filepath when a URL matching the pattern is requested.

I suspect you will want to use the second code fragment if you are using this code to support search-engine-friendly URLs.

Jim

ukgimp

8:07 am on Oct 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks jd for the clarification on a few things.

The weird thing is that the rules I had work on the live website, although I do intend to clean up my act.

I do however have a problem with serving multiple sites;

See example here
[webmasterworld.com...]

Multiple sites serve fine but I can have multiple htaccess files. In the end I managed to put the rewtite rules into the httpd.conf file using the

<Directory />
notation within the virtualhost container. It would be nice though not to have to restart the server each time, which is where it was good to have htaccess access.

Is that a simple one to consider.

cheers