how to setup pretty urls and mod rewrite rules on linux apache2 web server

View previous topic View next topic Go down

how to setup pretty urls and mod rewrite rules on linux apache2 web server

Post by jamied_uk on 17th July 2015, 16:24

First type this command
Code:
a2enmod rewrite


Now this command

Code:
sudo gedit /etc/apache2/apache2.conf

Now look for the folder of your www folder




Example below shows what it should be for this to work.
Code:

<Directory /var/www/html/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>


now restart your web server (example of how to alias this as its very comon to want or need to restart your apache server!

Code:
alias srest='sudo /etc/init.d/apache2 restart'


now type


Code:
srest



Type password when asked and vala!

This is an example of your .htaccess file to enable a custom pretty url!

Navigate to your www folder and right click, select terminal and type the following command

Code:
sudo gedit .htaccess


 (# is a commented out line).

Code:

RewriteEngine on
# Redirect Rule
RewriteCond %{THE_REQUEST} \?u=([^&\ ]+)($|\ )
RewriteRule ^ /%1? [L,R=301]
# Redirect Writeback
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /user.php?u=$1 [L]






For more information about alias and making it perminant alias search this forum for the word alias


Thanks For reading! Enjoy!
avatar
jamied_uk
Admin

Posts : 2268
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum