Home > Enterprise >  Why htaccess not working for mobile browser?
Why htaccess not working for mobile browser?

Time:07-24

I have website (mzadkm.com) try to RewriteRule short url to app.php page .

So if user browse "mzadkm.com/app" will show "mzadkm.com/app.php" page

RewriteRule ^/app /app.php [L,R=301]

It's work on Computer , but on mobile browser give me 404 page

Any ideas

CodePudding user response:

That probably is what you are looking for:

RewriteRule ^/?app /app.php [L]

The documentation clearly says, that the pattern in a RewriteRule get's applied to the relative path of the request if the rule is implemented inside a distributed configuration file. That means you actually want to match the path app and not /app here. Which is why your rule did not get applied. The ^/?app is a variant to accept both path notations, relative and absolut, which means the same rule can get implemented in the central configuration or likewise in a distributed configuration file (".htaccess").

I took the liberty to also remove the external redirection you showed ("R=301") since that most likely is not what you want, according to the phrasing of your question. Instead you want an internal rewrite .

You need to take care however that you do not implement a rewriting loop. Which would result in failing requests and an "internal server error" (http status 500).

One approach would be that:

RewriteEngine on
RewriteRule ^/?app$ /app.php [L]

Here another one:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?app /app.php [L]

Why things looked fine on your computer, but not on a mobile browser is unclear. Since the same rules get applied and the requests look the same there has to be another reason for that. I suspect you looked at a cached result of a previous attempt somewhere. Remember to always use a fresh anonymous browser window when testing. And to check the response you receive back inside your browsers network console.

  • Related