I've been searching around and trying all sorts of different approaches, but I can't seem to figure out what's wrong.
I have the following piece of .htaccess code:
Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
# Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
It works fine on the production server, so that insinuates that the config file is set up okay there.
I'm trying to develop for this site locally though, and there I get 404 errors saying that the file does not exist when I go to localhost/example/login (which corresponds with domain.com/login).
I have tried different settings, setting AllowOverride All, checking if mod_rewrite is enabled in phpinfo(); and what not. But I can't seem to figure out what's wrong.
Any suggestions?
check out if mod_rewrite is enabled. Don`t forget to restart apache.
Check your virtualhosts, is allow override is on?
Related
I have a site that is live on AWS - Wordpress, latest version, custom theme
It works fine in MAMP on my laptop, but on the live site, none of the pages besides the homepage work with the permalinks as /%post-name%/
I can make the permalinks work if I change them to default.
I don't think it has to do with htaccess, I've tried scrubbing it, we made some edits to it, and that has not made a difference.
Here are the contents of htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ucampaign/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ucampaign/index.php [L]
</IfModule>
I think it has to do with settings in the AWS instance, which I know can get complicated. But I wouldn't know where to look.
Thank you for looking at this, if there's more information needed to figure this out, I will be happy to provide :-)
Looks like a missing mod_rewrite. check apache config for that. Also, make sure Apache is reading the .htaccess file. When I say check to make sure the .htaccess is being read, does the server throw an error when you place junk inside the .htaccess file? What type of OS are you running on AWS?
I have a webapp written in Laravel that needs to run in a folder on a web host.
The app will have to be accessible via hostname.com/webhit/. This will point to the app's home page.
I only have one route:
Route::controller('/', 'HomeController');
HomeController's getIndex needs to serve the home page. This works.
However, as soon as I want to go to something like hostname.com/webhit/login, I get a 404 from Apache.
Obviously, .htaccess is not working properly. I need it to, essentially, turn URLs that look like hostname.com/webhit/login into hostname.com/webhit/index.php/login.
I have a .htaccess file in www/webhit (where index.php is located) that looks like this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ webhit/index.php/$1 [L]
</IfModule>
I am not very familiar with .htaccess file syntax, but I believe it's doing something wrong.
Edit:
I did it. My .htaccess was wrong (it actually causes a redirect loop), but the issue was that it wasn't even being parsed by Apache (hence the 404 instead of a 500 due to >10 redirects in a request). I did the following steps in order to get everything to work:
Enable mod_rewrite and restart Apache (plenty of docs out there on how to do this)
But wait, there's more! By default, Apache on Ubuntu prevents URL rewrites. See this site. Most importantly, the following fragment from the URL above is very important: "By default, Ubuntu's Apache will ignore the directives in your .htaccess files." You will need to actually enable rewrites by editing \etc\apache2\sites-available\default and setting AllowOverride to all (see link above for more details).
Reload the configuration (or just restart apache).
Make sure you're using the correct .htaccess. My original version actually has a redirect loop in it. See the selected response for the correct version.
After this, I got it to work. I hope it helps future programmers having a similar issue!
Check default server requirements - laravel .htaccess file works for most situations. Try with this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I would suggest you to use resourceful controllers - mappings from your route to your controllers methods are much more clear, and you'll get full
resource with one command (routes,models,views,controllers)
I'm having some issues figuring out how to use an htaccess file. I've got apache/php installed on an ubuntu system and mod_rewrite is turned on (php_info() states that it's in the list of loaded modules). The web server works, displays html and php files, so I'm happy with that.
What I'm trying to figure out now is how to use an htaccess file properly. I created a directory, /data, with an index.php file in it. All I want it to do at the moment is just display the $_REQUEST variable so I can see if things are working the way I assume they should.
Example: If I type in the following URL: localhost/data/info1/ I want the htaccess file to access localhost/data/index.php?request=info1
However, no matter what I enter in to the htaccess file, I keep getting 404 errors, and I'd like to understand why.
Here's my htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule data/(.*)$ data/index.php?request=$1 [L]
</IfModule>
I've made no changes to the config file, to activate mod_rewrite, I used the ubuntu a2enmod command so ubuntu did it for me. After that, I restarted apache.
What I can't figure out is why this doesn't work. My assumption is that there's still some sort of configuration I need to do on the server end, but I honestly don't know what. Is there any advice anyone can offer me?
Here's the fix:
RewriteRule ^data/(.*)$ data/index.php?request=$1 [L]
(You were missing a ^)
EDIT:
In the OP, you have another leading / in the URL example, in this case it'd be:
RewriteRule ^data/(.*)/$ data/index.php?request=$1 [L]
I've installed Xampp as a web server and want to make clean URLs for one of my projects. So I put these simple lines in .htaccess file in the root of this project:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Also I made links in this project like this:
About Us
I expected to go to localhost/this_project/about/, but it does not work. I go to localhost/about/ and this is wrong. How can I solve this problem?
I also have put this line in the 2nd line of .htaccess file, but no change happened.
RewriteBase /this_project/
Attention: There are many directories in htdocs folder for each project.
You htaccess looks OK so I guess you are missing
AllowOverride All
In the VHOST <directory> block. If you server will fail after you add AllowOverride make sure you enabled mod_rewrite.
I am trying to setup a website on my Mac using MAMP. I put my website content into a folder under
/Applications/MAMP/htdocs/positweb
"positweb" containins index.php which tries this redirect:
header("Location: web/main");
Along index.php I have .htaccess file, which came with the website:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I have also enabled "AllowOverride All" inside
<Directory "/Applications/MAMP/Library/htdocs">
element in both httpd.conf and httpd-std.conf files.
Now, my problem is that these redirects don't work on my setup. Chrome says that the link "http://localhost/positweb/web/main" is broken, Firefox says that index.php is not found.
All of the php/.htaccess files are exact copies of a working version of the site. I tried playing around with Apache settings like I described above, but with no luck, and now I don't know what else to try.
My MAMP version is 1.9.5.
Any suggestions are appreciated. Thanks.
Try changing your base_url in the bootstrap.php from / to /positweb
And make sure you've got FollowSymLinks turned on in your httpd.conf.