Question

I have a domain name www.jannatband.com, when I access the url:

http://jannatband.com/me/asd

It successfully echoes the value asd, the original url is like:

http://jannatband.com/me/index.php?u=asd

HTACESS CODE FOR THE ABOVE:

# .htaccess
RewriteEngine on
RewriteRule ^[aA-zZ]+$ index.php?u=$0

but when I try to convert the same url to

http://me.jannatband.com/asd

using this .htaccess code:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^me\.jannatband\.com$
RewriteCond %{REQUEST_URI} !^/me/
RewriteRule (.*) /me/$1

Its giving me a This webpage is not available error. What is wrong with this .htaccess code?

PS: the /me/ is an existing directory in the public_html.

Was it helpful?

Solution

You rewrite rules will change the URL once in your case. But you want to make the rewrite engine to work on the changed URL once again.

You can say so by specifying a flag, the next flag. From the manual:

'next|N' (next round) Re-run the rewriting process (starting again with the first rewriting rule). This time, the URL to match is no longer the original URL, but rather the URL returned by the last rewriting rule. This corresponds to the Perl next command or the continue command in C. Use this flag to restart the rewriting process - to immediately go to the top of the loop.

So be careful when you enable it:

RewriteRule (.*) /me/$1 [N]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top