2

I find I'm the only one coming up with bizarre behavior on my website. Now one of my extremely important links has malfunctioned.

This is the RewriteRule I have that malfunctioned:

RewriteRule ^m/?$ /x.php?MOBILEMODE=m&MAIN=1 [NC,L]

I then test my URLs http://example.com/m and http://example.com/m/ in CURL. http://example.com/m/ is processed correctly, but http://example.com/m takes me to a redirection page. In HTML source code, its this:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://example.com/m/?MOBILEMODE=m&amp;MAIN=1">here</a>.</p>
</body></html>

I'm using apache 2.2.

Is there a simple way to fix this so that http://example.com/m and http://example.com/m/ provide the expected result (of running the x.php script) instead of receiving a redirection message from apache?

I thought adding /? after m makes the slash optional and I thought this problem would only be caused by including R=301 in the options, but I guess I'm missing something?

Any ideas?

2

Never mind. I found the answer I needed to my problem.

It turned out I also had a folder named m with the file robots.txt in it. I then removed that entire folder and now the RewriteRule works.

| improve this answer | |
  • 1
    mod_dir (DirectorySlash) appends the slash to the physical directory after your internal rewrite and triggers the external redirect. Instead of making the trailing slash optional, you could make it mandatory (since mod_dir would always add it). (Or delete the physical directory.) – MrWhite Feb 15 '16 at 23:56
  • Ok that just brought some crazy memories now when I was trying to make a multi-slash remover as an apache module and its the mod_dir module that delayed completion of the project because it always wanted to add an extra slash. – Mike -- No longer here Feb 16 '16 at 4:04
  • here's a vote for solving problem by yourself ;) – Josip Ivic Feb 16 '16 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.