RewriteEngine on
RewriteCond $1 !^(index\.php|assets|zip|scripts|uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
This is the site
Notice, every link you click, the change is done in the address bar, but not on the page.
Whats the problem with this HTACCESS code?
Thnx in advance :-)
Your .htaccess code is right for what it meant to do.
Appending index.php internally so you have a cleaner url in your browser address bar. Be clear on your question.
What you meant by "every link you click, the change is done in the address bar, but not on the page" ?
Related
In the first place, I want to create a new homepage URL. So instead of www.example.com my new homepage (base) should be www.example.com/abc.
So no matter what the user types as an URL, for example www.example.com/blabla, we need to redirect him to www.example.com/abc/blablabla.
If I am correct, the following will do that:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/abc.*
Rewriterule ^(.*)$ /abc/$1 [R=301,L]
Now comes the problem.
My new base isn't abc, but π. The URL valid value of this 'globe' is %F0%9F%8C%90. So you would think it's easy and replace all abc's in the .htaccess snippet above and your done, but unfortunately that isnt't the case.
Hope someone can help me out.
Regards,
TK
UPDATE:
Going to www.example.com results in loop that looks like www.example.nl/%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0%25F0FC0.
Notice that besides the loop, the icon is not showed as well..
In my example the .htaccess looks like:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/%F0%9F%8C%90.*
Rewriterule ^(.*)$ /%F0%9F%8C%90$1 [R=301,L]
UPDATE 2:
Ok, I fixed the icon part by adding NE as an flag and backslashing the unicode characters..
RewriteCond %{REQUEST_URI} !^/%F0%9F%8C%90.*
Rewriterule ^(.*)$ /\%F0\%9F\%8C\%90/$1 [NE,R=301,L]
So:
www.example.com
now results in
www.example.com/π/π/π/π/π/π/π/.....
But still got the loop.. :(... anyone got an idea?
ANSWER:
Just replace abc with the actual icon π. Make sure you do this using an editor that can handle these unicode icons... PhpStorm can't, but TextMate or Sublime works just fine.
Notepad++ works fine, too ^^ maybe it helps.
I got an error with SEO linking..
this is what happens..
http://boznetwork.net/index.php?a=explore
If you click on a track (not the play button) but if you click on the title of the track. The orange load bar will not redirect you to the track page.
But if you open the track in a new tab then you will see the track.
What did I do wrong?
My .htacess file looks like this:
RewriteEngine on
RewriteCond %{request_filename} -f
RewriteRule ^(.*) $1 [L]
RewriteRule index/a/(.*)/id/(.*)/ index.php?a=$1&id=$2 [L]
and the links I changed it to:
<a href="'.$url.'/index/a/track/id/'.$row['track'].'/"
but before I changed the link it looked like this:
<a href="'.$url.'/index.php?a=track&id='.$row['track'].'"
Your first rule is bogus. It always matches, then rewrites to exactly the same thing. This prevents the Apache from reaching the second rule.
Remove your first rule, and everything should work as expected.
I recently with the help of SO solved my htaccess rewriterule issue:
Reuse subdomain in a rewrite rule
The result is that when somebody enters
whatever.example.com/anypage
in the adress bar, the htaccess automatically redirects to
whatever.example.com/somepath/whatever/anypage
What I wish to do is to find a way to just show whatever.example.com/anypage in the adress bar with the content of whatever.example.com/somepath/whatever/anypage displayed.
In the post I mentioned earlier, Jon Lin clearly mentions the following:
redirects always change what's in the browser's URL address bar
However I know some very frequent cases of url rewritting that would show in the adress bar let's say, for instance:
example.com/article-1-15
but actually showing the content of
example.com/somepath/somepage.php?article=1&otherparam=15
How could this apply to my case? I really wish to have a tiny url but it seems I missed something.
You may try something like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/([^/]+)$
RewriteRule .* http://whatever.example.com/somepath/whatever/%1 [L]
It will map:
http://whatever.example.com/anypage
To a resource at:
http://whatever.example.com/somepath/whatever/anypage
showing always in the browser's address bar:
http://whatever.example.com/anypage
UPDATED
If whatever is dynamic and is the same in the substitution URI, here is another option:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ([^/]+)\.example\.com.*
RewriteCond %{REQUEST_URI} ^/([^/]+)$
RewriteRule .* http://%1.example.com/somepath/%1/%2 [L]
This will work as long as both "whatever" in the substitution path are the same. If they are not, the last "whatever" has to be hardcoded, like this:
RewriteRule .* http://%1.example.com/somepath/whatever/%2 [L]
There is no other way as the incoming URL doesn't have it.
I'm using a bunch of ReWrite rules in my .htaccess such as these
RewriteRule ^brochure/([^/]+)/?$ brochure.php?cat_path=$1
It's all working great thanks to answers I found by searching this site. But I've got a tiny little snag.
This rule works perfecty at the moment
RewriteRule ^([a-zA-Z0-9_-]+)?$ $1.php It catches all my urls like www.mysite.com/shane and requestes shane.php - So far so good, but when I call www.mysite.com I need it to request index.php
Which rule could I use for this?
Thanks people.
UPDATE - For the sake of future users needing similar help.
My rule of ^([a-zA-Z0-9_-]+)?$ $1.php was causing the problem I mentioned above. The question mark ? is not needed in this type of rule, when you remove the question mark the index.php file in the directory returns to being the default landing page. Thanks to Tomalak for the Help.
You don't need any rule for it. Just make sure that .php default index files for the directory and it'll happen automatically.
Update
I think that your rule
^([a-zA-Z0-9_-]+)?$ $1.php
should in fact be
^([a-zA-Z0-9_-]+)$ $1.php
so that it does not conflict with requests where the filename isn't given (which you want to direct to index.php).
I think this is what you're looking for,not sure thought:
RewriteRule ^/$ index.php
You can either do as Tomalak says, and ensure the DirectoryIndex is set to load index.php.
Or close to what James says,
RewriteRule ^/?$ index.php [L]
I'm a little stuck in here. I need to get some help with this subdomain-situation.
I need to redirect http://dynamicsubdomain.example.com/ to
http://dynamicsubdomain.example.com/account/welcome.html.
How do I do this? I tried several things but all without result. The main problem is that I can't fetch the entered dynamic subdomain from the %{HTTP_POST} string from mod_rewrite.
Another issue would be that it's creating and endless loop. So it only needs to redirect on these conditions, not when there's a URL like http://dynamicsubdomain.example.com/test/page.html. Because else it will create and endless loop. It's just for the starting page from the website.
I hope y'all can help me out, it's one of the last but important things from my project.
Thanks in advance!
There are several options on the URL redirection wiki page. For example, how about dropping an index.php in the root that redirects to the destination?
header("Location: http://dynamicsubdomain.example.com/account/welcome.html");
Why does the domain matter so much if you are staying on the same domain, and just redirecting to a different path?
The UseCanonical setting in Apache may have an effect on this, but it is defaulted to on, which preserves the host and port specified in the request.
RewriteRule ^/$ /account/welcome.html [R,L]
Hey guys, thanks for your support/help but I found the solution myself. Quicker than I thought :)
This is what does the trick, I hope I can help someone with this:
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteCond %{HTTP_HOST} ^([A-Za-z0-9]+).example\.com [NC]
RewriteRule ^ http://%1.example.com/account/welcome.html [L]
#gahooa: I need to do this because my mainpage example.com is just a sort of landing-page with no special things. The extra part of the URL "account/welcome.html" is for showing a page related to the "subdomains"-account (gahooa.example.com for example will show your profile page). In my app I catch up the subdomain by a preg_match so it knows witch account it has to load. I hope I'm clear :) But thanks anyway!
This is my first time i'm using Stackoverflow but it actually works great! Quick replies from experts, great work! I definitely will come back :)
If you really want to use HTTP_HOST:
RewriteRule ^$ http://%{HTTP_HOST}/account/welcome.html [L,R]
But like gahooa already said you donβt specify an absolute URL if you stay with the same host. The URL path will suffice:
RewriteRule ^$ /account/welcome.html [L,R]