Reputation: 686
This is my link: http://localhost/test/index.php
Now i want to change it to look like this: http://localhost/home/
So i create a .htaccess file and placed it inside the test folder.
This is my .htaccess code:
RewriteEngine on
RewriteRule ^test/index.php$ home/
mod_rewrite is also enabled.
But anyway this rule is not working for me and browser is redirecting me to the original url http://localhost/test/index.php
. However i tried this rule online and it seemed working there. Here's the snapshot of the website where i tested the rule.
Upvotes: 2
Views: 7950
Reputation: 873
Try these paths:
In terminal run a2enmod rewrite
and restart apache.
If it was done , Do the following,
go to this directory,
cd /etc/apache2/sites-available/
sudo gedit default
Replaces this line :
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
and change it as below
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Then start apache server
sudo service apache2 restart
sudo gedit /etc/apache2/apache2.conf
Add following in the end
```
ServerName localhost
Include /etc/phpmyadmin/apache.conf ```
Also set AllowOverride All
for /var/www
Directory
Then follow these steps
sudo adduser <username> www-data
sudo chown -R www-data:www-data /var/www
sudo chmod -R g+rw /var/www
Restart apache
Done!!!
/var/log/apache2/error.log
if still facing problemsUpvotes: 1
Reputation: 784958
You need to have 2 complimentary rules:
RewriteEngine on
RewriteBase /
# external redirect for chancing URL
RewriteCond %{THE_REQUEST} \s/+test/index\.php[\s?] [NC]
RewriteRule ^ home/ [L,R=302]
# internal routing to actual URL
RewriteRule ^home/?$ test/index.php [L,NC]
Upvotes: 0