i am currently trying to learn about clean urls. i was using windows once.
i switched to ubuntu when suddenly my .htaccess seems to be not working
here is my htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
so i have this url
http://localhost/index.php/my_name/
i was expecting it to say the 'my_name' string in the browser
hello my_name
but it would only work whenever i add a '?' in the uri
http://localhost/index.php?/my_name/
i am pretty sure mod_rewrite is enabled. i even checked my phpinfo()
It sounds like the rewrite module is disabled. Edit your apache configuration and load the dynamic module for mod_rewrite if available. It would look like this:
LoadModule rewrite_module modules/mod_rewrite.so
If you're using Ubuntu, run sudo a2enmod rewrite to enable the module following by restarting the Apache server:
sudo /etc/init.d/apache2 restart
Found a solution. dumped the $_SERVER variable and used the REQUEST_URI index since QUERY_STRING does not display anything. will +1 Lekensteyn's answer since it led me to the right path
Related
I get error 500 Internal Server Error when using the below lines in .htaccess file in the main directory of the website.
RewriteEngine on
RewriteRule ^ar/?$ index.php?lan=ar [L]
RewriteRule ^en/?$ index.php?lan=en [L]
My intention is load website.com/index.php?lan=en when entering website.com/en. What could be the issue here?
Have you check if the mod_rewrite is enabled on your apache server ?
If you are on Windows, check the httpd.conf file inside the apache/conf directory on your web server.
On linux like Debian / Ubuntu, check if there is the file rewrite.so in /etc/apache2/mod-enabled/ directory. Otherwise, add the module with the command a2enmod rewrite && service apache2 restart
I am also not seeing an issue here might be some other rule or conflicting htaccess, but you can do that easily by,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ index.php?lan=$1 [QSA,L]
I need some help with laravel 4 application i need to remove Index.php from url i have tried the solution that has been mentioned in laravel documentation
Pretty URLs
Apache
The framework ships with a public/.htaccess file that is used to allow URLs without index.php. If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.
If the .htaccess file that ships with Laravel does not work with your Apache installation, try this one:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
any Suggestions :) ?
FOR LAMP SERVER
Try the following steps,
Activate the mod_rewrite module with,
sudo a2enmod rewrite
and restart the apache
sudo service apache2 restart
To use mod_rewrite from within .htaccess files (which is a very common use case), edit the default VirtualHost with
sudo nano /etc/apache2/sites-available/000-default.conf
Search for “DocumentRoot /var/www/html” and add the following lines directly below:
<Directory "/var/www/html">`
AllowOverride All
</Directory>
Save and exit the nano editor via CTRL-X, “y” and ENTER.
Restart the server again:
sudo service apache2 restart
this worked for me
<Directory "/var/www/html">`
AllowOverride All
</Directory>
uncomment 'LoadModule rewrite_module modules/mod_rewrite.so' in apache httpd.conf
in 'public' folder check .htaccess file (created by default)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I have read long posts and threads but nothing works then i found this and it works for me.
The easiest way to do this (and the way I always use) is to open up your Command prompt or Terminal and cd into the main directory of your project then run "php artisan serve". That's it. You're done. Don't believe me? Check out http://localhost:8000 and admire your Laravel work.
http://michaelbrooks.co.uk/post/laravel-localhost-removing-public-index-php
just go to your apache settings folder, i use wamp so myne is
C:/wamp/bin/apache/apache2.4.9/conf/httpd.conf - file
// located on line 154 precisely...
#LoadModule rewrite_module modules/mod_rewrite.so
// to
LoadModule rewrite_module modules/mod_rewrite.so
restart WAMP and BOOM!.. it works.
mod_rewrite apache module may not be enabled by default. enable it and retry.
Try this:
a2enmod rewrite
And it will works
I want to basically be able to goto, for example: www.example.com/my/folder/
where the subdirectories /my/folder/ don't exist, and have it redirect to index.php?path=/my/folder, while still keeping the original URL.
I hope this makes sense. I basically have no idea where to start with this. I'm guessing it's something with .htaccess, or http.conf or something, but I have no clue.
I basically want some direction on where to figure out how to do this, or some suggestions.
I always liked borrowing from the Wordpress .htaccess file myself
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This little bit of code will rewrite anything that is not a file and send it to your index.php file. You can then parse $_SERVER['REQUEST_URI'] for anything you need from the URL itself.
It depends on what web server you're running. If you're running Apache, then yes, it's in the .htaccess file or the VirtualHost file. In addition, mod_rewrite will need to be enabled on your Apache server for this to work.
sudo a2enmod mod_rewrite
sudo service apache2 restart
Other web servers will have it in different locations and require different commands.
I have the following in my .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^directory/(.*)$ directory/index.php?id=$1
What I'm trying to achieve is this:
When the URL www.example.com/directory/10 is visited, the page www.example.com/directory/?id=10 is displayed on the browser without altering the appearance of the URL.
The above code creates a 500 Internal server error though.
Does anyone know where I'm going wrong?
Your code is guaranteed to generate 500 internal server error because it is causing infinite looping. Reason is that your matching URI pattern is: ^directory/(.*)$
Which matches your URLs before and after rewrites. And once it reaches max allowed internal rewrite limit Apache throws 500 internal server error and bails out.
Change your code to this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^directory/(.*)$ directory/index.php?id=$1 [L,QSA,NC]
Above code has an extra RewriteCond %{REQUEST_FILENAME} !-f that will make sure to disallow subsequent execution of RewriteRule after first time since /directory/index.php will be a valid file.
I have got the same issue and found that "rewrite" module is not yet enabled in my case. So I need to enable it and then restart apache server:
Enable "rewrite" module: sudo a2enmod rewrite
Then restart apache server: sudo service apache2 restart
Hope this will help anyone.
You should try adding a forward slash to the front:
RewriteRule ^/directory/(.*)$ directory/index.php?id=$1
I've been caught out with that before.
Alternatively use the RewriteLog and RewriteLogLevel to debug, and look at the Apache error and access logs for further info:
RewriteLogLevel 3
RewriteLog ${APACHE_LOG_DIR}/rewrite.log
That will leave a log file in your apache log directory. In my case that is /var/log/apache
If you are using CodeIgniter and is in error problems 500. Follow the solution.
So to delete the segment "index.php" of URLs in CodeIgniter, you need to do 2 things. The first is to edit the /system/application/config/config.php file, changing the value of index_page policy to empty:
$config['index_page'] = '';
The second step is to create a file .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
And that's it! From now on, the URLs of your site/system made with CodeIgniter will no longer have the thread (called "annoying" by some) "index.php".
Another day searching for a strange error on Apache.
Working on my Docker Apache 2.4.48 alpine container. But not in production.
Here is the difference (just a dot):
Not working on hosting provider
RewriteRule ^public/(.*)$ ./public/index.php?route=/$1 [L,QSA]
Working on hosting provider
RewriteRule ^public/(.*)$ /public/index.php?route=/$1 [L,QSA]
Just uncomment #LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
Because by default it was disabled/commented
I am using apache 2.2 in ubuntu 12.04 in Amazon EC2.
I enabled mod_rewrite using
sudo a2enmod rewrite
and able to see with
apache2ctl -M
now I wrote the .htaccess code as following and is not working
# Redirect everything in this directory to "good.html"
Options +FollowSymlinks
RewriteEngine on
RewriteRule .* good.html
Here is my contents of /etc/apache2/sites-available/default
http://pastebin.com/urNfmqan
when I add
LoadModule rewrite_module modules/mod_rewrite.so to the httpd.conf I get this
waiting [Thu Apr 11 18:44:12 2013] [warn] module rewrite_module is already loaded, skipping and htaccess is not working even then ( I presume in apache2.2 we don't edit httpd.conf to enable rewrite_mod but as per anubhava comments I modified the question)
Try this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /good.html [QSA,L]
</IfModule>
You should change the Base and the second element in the rewrite rule to whatever your directory is if it's not root.
Looks like you will have a rewrite loop. Apache rewrite doesn't run the rules once, but once for every time a path is requested. So on first load it rewrites .* to good.html. Then it makes an internal request for good.html and re-processes the rules again, rewriting again and makes another internal request to infinity. Revent's answer tries to solve this by checking if the file exists. You get index.html in his rules because index.html exists. If you removed index.html the file wouldn't exist, the rewrite condition would match and the rule would rewrite to good.html. When re-processing the rules, the file exists, the condition fails and redirect stops after that.
To fix, you can add the [L] flag after your rewrite rule to tell apache to stop processing rules after this one runs which should stop the loop. If that doesn't help, you can add a rewriteCond to check that the request_filename is not good.html causing the rule to fail after redirect.