Home How to use RewriteRule in htaccess using XAMPP
Reply: 1

How to use RewriteRule in htaccess using XAMPP

Greg Ostry
1#
Greg Ostry Published in 2017-12-05 19:40:45Z

How do I get rid of the folder name using .htaccess and XAMPP.

I saved the folder in --> xampp/htdocs/myproject

In myproject folder there are an index.php and .htaccess files.

RewriteEngine On
RewriteBase /myproject/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

index.php

<h1>index</h1>


<?php   

    var_dump($_SERVER["REQUEST_URI"]);

This redirects me to the index file but when i var_dump requested uri i'm getting also myfoler name.

example:

http://localhost/myproject/contact

i'm getting -->/myproject/contact

Is this possible to get rid of this foldername/path using .htaccess ? In this case the /myproject/.

Phl3tch
2#
Phl3tch Reply to 2017-12-05 19:58:02Z
RewriteRule ^myproject/(.*)$  $1

This will take any url of the pattern "myproject/whatever" and rewrite it as "whatever". The string (.*) tells .htaccess to take everything after "myproject/" and store it in a backreference, which is referred to in the rewrite portion of the rule as $1. Hope this helps.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312369 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO