Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

append path directory to url using htaccess

how could i get Apache to redirect

http://localhost/index.php
http://localhost/create/index.php
http://localhost/create/contact.php
http://localhost/engage/page1/services.php

to

http://localhost/Project1/index.php
http://localhost/Project1/create/index.php
http://localhost/Project1/create/contact.php
http://localhost/Project1/engage/page1/services.php

respectively?

Essentially I need to append "Project1" (or whatever other string I see fit) to the BEGINNING of the url path

Thanks

like image 924
AlexMorley-Finch Avatar asked Nov 05 '22 05:11

AlexMorley-Finch


1 Answers

You can use negative lookahead like this:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# redirect to /Project1/ if it is not already /Project1/
RewriteRule ^((?!Project1/).*)$ Project1//$1 [L,NC]
like image 80
anubhava Avatar answered Nov 11 '22 15:11

anubhava