.htaccess - Localhost working in a folder problems - .htaccess

I'm working localhost on my mac with MAMP. And I'm trying to do some mod_rewrite with .htaccess. I think all my problems is about that I'm working on a URL like this: localhost:8888/folder/index.php.
How do I either "remove" the /folder/... Or make .htaccess work with /folder/ having in mind that I wanna remove it as soon as my project goes live? *I would prefer to "remove" the /folder/ to make it look more like when my project goes live.
If I am trying to for example "remove" the index.php like this:
#Removes index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
It's jumping all the way back to root: localhost:8888/ instead of localhost:8888/social/.

Had the same problem and just found a solution.(I know i may be late to this post, but might help some else)
The problem I had was with the my local web enviorment. I tried it on the server and everything was working! So found out that I just needed to set up the Virtual Hosts for my sites in apache and everything worked great!
I did this with the help of this stackoverlfow post: How to set root directory to a subfolder and this article on how to do this on a windows PC: Setting up Virtual hosts in win 7
Hope it helps,
Cheers!

Related

Redirect not works in Server but works in Localhost

I use CodeIgniter 3.1 in my project. Everything is running well in localhost, but when I upload to server, all controllers that using redirect didnt work. It only shows blank page. Here my htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
Please, help me find this solution. Does CI version is the main problem? or the htaccess itself? This is my first time upload my project to server and I hope I didnt miss something important .. thanks
[EDITED]
I use another server, it works fine. Maybe the problem is in the server.
[EDITED]
Horray... Problem solved. Just put ob_start() at the begining every .php.
(more information , visit http://kakaeriel.com/mengatasi-cannot-modify-header-information/)
Thanks for everyone who helped me find this solution.
I assume your host could have same config as Godaddy's. You could try this https://github.com/bcit-ci/CodeIgniter/wiki/Godaddy-Installation-Tips
In /application/config/config.php set $config['base_url'] like this
$config['base_url'] = 'http://[hostname]/'; //like www.google.com

Rewrite rule behaving differently between environments

I have two environments, both using Bitnami installations (if that makes a difference). My local environment is WAMP and works correctly. The second is on EC2 using LAMP and does not work correctly. I've done some basic checking and things seem to be setup the same but still give different results.
RewriteEngine On
RewriteRule ^([^/.]+)$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA]
The .htaccess page is the same, as are the folder configurations. I have all files in the root folder.
-root
-index.php
-study.php
If I go to //localhost/study/ it correctly redirects to index.php. However on my EC2 instance, it instead goes to study.php. Even if I go to //ec2/study/random/2021/bleh/ it will redirect to study.php. Going to //ec2/random/ will however go correctly to index.php since I do not have a "random" folder.
I've run out of ideas of where to look for configurations differences (I even set "AllowOverride All" in the httpd.conf file and tried -MultiViews). Any help/ideas would be greatly appreciated!

Mod Rewrite tweak to ignore asset directories

I'm configuring Expression Engine on Windows using IIS and have ISAPI v3 Rewrite installed.
It's partly working. The main site and subpages work but needs to be modified because some web page assets are stored in similarly named directories.
The recommended Rewrite provided by Ellislabs is this and I've modified it a little to work with our Win 2012 IIS 8 server:
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) abc/$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ abc/index.php?/$1 [L]
For example, the URL http://oursite.example.com/abc works.
Subpages are mostly working and I suspect this applies to any page really but I'm noticing it on subpages. It removes index.php and mostly loads, such as http://oursite.example.com/abc/subdept/page/
However our developer has some assets kept in a server directory named /uploads/abc/ so if a page refers to this directory, it fails to load those assets because it contains the same name, "abc".
Thus, what is the best way to handle this?
I'm guessing I can either tell it to ignore "uploads/cls" or correct the current Rewrite so that it only looks at the first "abc". I'd like for the solution to cover most similar issues that would arise so I don't have to keep modifying it. We have 12 sites and I'll have to apply the solution to each one.
Everything I've tried hasn't worked.
Also, I thought !-f and !-d would tell it to ignore it if the file or directory existed and that doesn't seem to be working as I'd expect here because these images in /uploads/abc/ do exists.
Thanks!
--
Additionally just trying to get it to work at all, I tried adding a htaccess file with "RewriteEngine Off" in the /uploads/abc/ directory and that failed to fix it.
I also tried to add this after each comment and it fails to fix it:
RewriteCond %{REQUEST_URI} !^/excluded-folder/.*$
Seeing how both of the above attempts fail to fix it, I'm wondering if there could be something else going on. Any ideas?
My rewrite was fine. The problem turned out to be code within an Expression Engine template that the in house developer created. They updated the code and the images are loading fine now.

Codeigniter url/links with mode rewrite htacess: object not found

I am working on project using codeigniter for the first time with bootstrap 3.
My application and system folder from CI is located outside my 'project.main' folder. Everything works fine until I try to use .htaccess in my project.
I am using an XAMPP server and I already loaded the rewrite module and as well as the AllowOverride All and restarted my server.
My url now looks like this 'http://localhost/project.main/' ..
Now my question is since I already removed the 'index.php', my navbar links in bootstrap was like this
'<a href='<?php echo site_url("pages/view/about"); ?>
but if I click it I am directed to the url
'http://localhost/project.main/pages/view/about' which gives me
Object not found' error page.
But if I use href=' <?php echo site_url("index.php/pages/view/about"); ?> I am routed to the right page.
Which is the right way of doing it? and under my config.php I have this $config['uri_protocol'] = 'REQUEST_URI '; is it necessary that uri_protocol match what is on the .htaccess under RewriteCond %(REQUEST_URI)..?
What i read in github there are two versions of .htaccess.
You didnt mention changing index page to blank inside config.php ? In case of emergency I give you my simple htaccess. It works when moving application and system folders out of public.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Also try to switch uri_protocol option.
Here's the ultimate solution for index.php How to remove "index.php" in codeigniter's path .

Rewriting URL with .htaccess local in XAMPP

My .htacces begins with
RewriteEngine on
RewriteBase /
(I tried it also without RewriteBase...)
I tried all of the following rewriting rules to rewrite the URL
index.php?page=news
to
/blog
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/blog$
index.php?page=$1 [L]
RewriteRule ^([^/]*)/blog$ /sites/blog/index.php?page=$1 [L]
RewriteRule ([a-zA-z]+)/([a-zA-z]+)/blog$ index.php?page=$1 [L]
Nothing works - no error. Mod_rewrite is installed and working. I restarted Apache and MySQL everytime I changed something in my .htaccess.
I also want to change my URLs which looks like this... index.php?page=single_news&category=release&id=9&headline=Beastie%20Boys%20III
...into: blog/release/9-Beastie-Boys-III
I am lost. Hope you can help me.
First of all, upload your .htaccess and other files (whole project) to some working, ready hosting server. And check, if your rewriting works OK there. This will let you know, if this is problem with .htaccess or XAMPP itself. I had many strange problems with using .htaccess locally, under XAMPP, that were magically gone, after files were uploaded to Internet hosting.
For example, I don't have working autorization using .htaccess locally, because right after I provide correct login and password I see exactly the same error message as you mentioned. As for me, I'm more than sure that this problem is purely related to incorrect interpretation of .htaccess done by XAMPP (as everything works like a charm on production server), not by some mistakes in .htaccess contents.
I wasted (too) many hours on finding solution and left it. For right now, if I'm developing locally, I rename ".htaccess" to "htaccess", so it is ignored by XAMPP (Apache on-board of it) and re-enable it only when deploing files to production server. This approach maybe isn't to professional, but it saved me a lot of time and stress! :]
On the other hand, if your hosting also fail with the same symptoms, then you'll know, that this is not XAMPP releated problem and you have something wrong with your syntax.
Take a look here for a similar problem reported on StackOverflow.com, where (as I think) the cause is the same as in your issue.
Here's the solution to change links from http://www.domain.tld/index.php?page=blog to http://www.domain.tld/blog is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^\w+$ index.php?page=$0 [L]
RewriteCond %{THE_REQUEST} index\.php
RewriteCond %{QUERY_STRING} ^page=(\w+)$
RewriteRule ^index\.php$ /%1? [R=301,L]
and for links like: http://www.domain.tld/index.php?page=single_news&id=1&headline=This%20Is%20A%Headline
the solution is:
RewriteRule ^blog/(\d+)-([\w-]+)$ index.php?page=single_news&id=$1&headline=$2
After using this code, links looks like this: http://www.domain.tld/blog/2-this-is-a-headline
For your first question, try this:
RewriteEngine on
RewriteRule ^/blog$ /index.php?page=news

Resources