Mobile app version of vmapp.org
Login or Join
Hamaas447

: GoDaddy: RewriteCond in .htaccess not working with "beginning of the line" (^) I have .htaccess containing RewriteCond and RewriteRule. It used to work just fine (it's been a long time since

@Hamaas447

Posted in: #Godaddy #Htaccess

I have .htaccess containing RewriteCond and RewriteRule.

It used to work just fine (it's been a long time since I last checked), but now it has stopped working. I have narrowed it down to the following example.

Suppose I want to redirect mydomain.com/foo but not when foo occurs anywhere else; so, for example, don't redirect if the URI is /abc/foo, /abcfoo, or /foobar.

Here is my current .htaccess file:

Options -Indexes +FollowSymLinks -Multiviews

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/foo$
RewriteRule . /redirect.html [last,redirect=temp]


I have tried changing ^/foo$ in various ways, but I can't get this to work.

The following all work as expected:

foo Redirects wherever foo appears, e.g. /abcfoobar
foo$ Redirects whenever foo appears at the end, e.g. /abc/defoo
/foo Redirects whenever /foo appears, e.g. /abc/foobar
/foo$ Redirects whenever /foo appears at the end, e.g. /abc/foo


The following always return 404 Not found, no matter what I put as the URI.

^foo
^/foo
^/foo$


I don't know what's going on.

Please help me fix this. In case it helps, I'm using GoDaddy hosting.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Hamaas447

2 Comments

Sorted by latest first Latest Oldest Best

 

@Moriarity557

I have just discovered the solution! This seems to be a GoDaddy special.

Domains in GoDaddy are kept in subfolders; e.g. mydomain.com might be held in a subfolder called md.

Curiously, the start of %{REQUEST_URI} includes this string. Therefore, my RewriteCond should have read:

RewriteCond %{REQUEST_URI} ^/md/foo$


It is not needed if the string does not necessarily start at the beginning. This explains my strange results.

I have edited my title to show that this applies specifically to GoDaddy, in the hope that this helps someone else.

10% popularity Vote Up Vote Down


 

@Ann8826881

I’m not sure what the problem is in your case (I tested your snippet and it works as expected), but maybe this works for you:

RewriteEngine On
RewriteRule ^foo$ /redirect.html [redirect=temp,last]


I’m not an .htaccess expert, but I guess this would even be faster, because the RewriteRule pattern gets processed before RewriteCond.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme