I have this in my .htaccess file...
RewriteEngine on
RewriteRule ^/invite$ /invite.html
It's meant to let a user access this url:
http://mysite.com/invite
and display the invite.html page. I don't want to redirect the user, but just show them the invite.html page from a better looking URL.
When I browse to http://mysite.com/invite though, I get a 404 not found error.
Is there anything I'm doing wrong? I've tried looking at tutorials for using mod_rewrite but I seem to be doing what they're telling me too...
Thanks!
I don't think there should be a / in that RewriteRule:
RewriteEngine on
RewriteRule ^invite$ invite.html
Did you make sure that AllowOverride All is set for the directory where the .htaccess file lies? Else the file might be ignored.
If this isn't the case, you should check out Apache's log files for more hints (/var/log/apache on Linux).
You're missing a RewriteCond directive. That's the one that does the actual testing Condition to match a URL. The RewriteRule is invoked only when one or more RewriteConds are matched.
Related
I am wondering to know about this is it possible or not. If yes then please help me.
I want to change this URL:
http://domain.com/profile/admin
to
http://domain.com/admin
Where admin is username of profile user.
Why I am thinking it is impossible like the URL is already rewritten in .htaccess or somewhere.
You provide a little to less context to give a definitive answer but it must certainly be possible. It all depends on how you have setup your code and webserver now and in what degree you are allowed to modify any of them.
You can use below snippet in your .htaccess file -
<IfModule mod_rewrite.c>
RewriteEngine on
RedirectMatch 302 ^/$ /admin
RewriteRule ^/profile (.*) $1 [R=301,L]
</IfModule>
This snippet won't work if the URL- http://domain.com/profile/admin is auto-generated in between the application.
First of all this method clearly working on github, for example pages showing done:
https://github.com/account
https://github.com/inbox
There is no .php extension at all + not needed ?page=account or ?page=inbox
In my opinion it's done via .htaccess.
Maybe someone knows how it should look in order to archieve same effect like github site ?
This can be achieved using mod_rewrite for apache
You put a .htaccess file in your document root and give it rules (Regular Expressions) to match the called URLs with
It looks similar to this:
RewriteEngine On
# rule to call MyPage.php if you call the URL http://yourdomain.com/MyPage
RewriteRule ^(.*)$ $1.php
# rule to add GET params
RewriteRule ^(.*)$ index.php?page=$1
There are several tutorials regarding mod_rewrite on the internet
I have a short question about url rewriting...
I have a website. Let's say http://www.example.com/
with some subsites:
http://www.example.com/a.php
http://www.example.com/b.php
etc...
and some "special" urls like
http://www.example.com/c.php?i=1#link1
http://www.example.com/c.php?i=1#link2
http://www.example.com/c.php?i=2#link1
Now I would like to write a .htaccess file to convert current urls into rewritten urls like
http://www.example.com/a/
http://www.example.com/c/1/#link1
I'm not an expert in url rewriting, so could somebody please help me?
Best reagards.
RewriteRule ^a$ a.php [L]
RewriteRule ^c/(.*)/(.*) c.php?i=$1$2
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^a.php a/
RewriteRule ^b.php b/
Should work as far as your static pages go, you can not rewrite the hash because the hash is not sent to the server (as discussed here). If you need to rewrite the hash I would suggest changing the hash to another GET variable (eg u), in that case just add this to your htaccess: RewriteRule ^c.php?i=(.*)&u=(.*) c/$1/$2. If you simply intend to leave the anchor though, you can omit it from your rewrite and everything should be fine (...becuase the server never sees the hash/pound symbol), and in that case you should add this to your code RewriteRule ^c.php?i=(.*) c/$1/.
I'm wondering if there is something wrong with my CI setup. If I load the base_url ie http://localhost/~User/project/
then it loads perfectly, adding the index.php before the default controller. However,
my config file has
$config['index_page'] = '';
As a test I returned this value to 'index.php'. When I loaded the base_url after this it returned: http://localhost/~User/project/index.php/index.php/controller/method
Is this what I shoul expect? I'm having big problems with my .htaccess file which doesn't seem to be working. I posted this as a separate question incase the two are unrelated.
UPDATE: I've now got the .htaccess working and the index.php has disappeared BUT ONLY IF TYPE THE FULL URL.
If I just type the base_url then it loads the default controller but still adds the index.php into the string.
To clarify...
If I type:
http://localhost/~User/project/controller/method
everything works as expected and the URL stays exactly like this. Similarly if I follow relative links then the correct controllers and methods are loaded with index.php appearing in the URL.
If, however, I only type:
http://localhost/~User/project
it redirects me to
http://localhost/~User/project/index.php/controller/method
The controller is the default that I have setup in my config file and I have also set
$this->config['index_page'] = '';
Have you followed this tutorial to the letter?
Try using the following .htaccess file, it has never let me down so far:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
SOLVED:
Ok this makes me feel really stupid, but I found the cause of the problem. I had a redirect function tucked away in MY_Controller that I'd completely forgotten about. Because previously i couldn't get the .htaccess to work, I'd hard-coded the redirect to include index.php.
Everything is now working as it should. Many apologies for wasting your time trying to solve a problem that didn't exist!
I am trying to figure how to make a .htaccess RewriteRule so a visitor views example.com/folder
but is served
example.com/f1/f2/f3/folder/index.php
where f1/... is just an arbitrary line of folders.
I have kicked mod_rewrite a little, and got some really weird results, none I was going for though.
I'm not quite sure what you're trying to achieve. This, however, might solve your problem. Basically it translates any query for /folder, /folder/ or /folder/... to /f1/f2/f3/folder/...:
RewriteRule ^folder(/.*)?$ f1/f2/f3/folder$1
EDIT
If you don't care about anything after site.com/folder, this should suffice:
RewriteRule ^folder$ f1/f2/f3/folder/index.php
EDIT #2
Rewriting the root (according to comment by OP):
RewriteRule ^(.*)$ folder1/folder2/$1 [QSA]
There may be other (better?) ways to translate the root, though.
Docs are available on the QSA directive.