Reputation: 1568
I am using the following .htaccess rule to make www.site.com/index.php convert into www.site.com/username
It's working pretty well but I am having problem with some pages I can't access for example other pages in the same directory, like settings.php only index.php acess is allowed. also I am having problem with a dropdown menu build with bootstrap in the same dir I am using include_once("menu.php"); in the index.php file the menu is showed but dropdown list is not showed.
I tested the menu without the .htacesss and dropdown works ok, I think the main problem is the .htaccess file, how to solve this?
Any alternative to my .htaccess code?
Here is the .htaccess code
# .htaccess
RewriteEngine On
RewriteRule ^([a-z0-9-_.]+)/?$ index.php?id=$1 [NC,L]
RewriteRule ^([a-z0-9-_.]+)/([a-z0-9]+)/?$ index.php?id=$1&goto=$2 [NC,L]
Here is the menu.php code
<li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle"><?php echo $_SESSION["username"]; ?> <b class="caret"></b></a>
<ul class="dropdown-menu" style="background-color: #333; color:white;">
<li><a href="#"><i class="fa fa-home" aria-hidden="true"></i> <?php echo $lang['MENU_HOME']; ?></a></li>
<li><a href="#"><i class="fa fa-user" aria-hidden="true"></i> <?php echo $lang ['PROFILE']; ?></a></li>
<li><a href="#"><i class="fa fa-shopping-cart" aria-hidden="true"></i> <?php echo $lang ['SHOOPING_CART']; ?></a></li>
<li><a href="#"><i class="fa fa-search" aria-hidden="true"></i> <?php echo $lang ['SEARCH']; ?></a></li>
<li><a href="#"><i class="fa fa-envelope" aria-hidden="true"></i> <?php echo $lang ['MESSAGES']; ?></a></li>
<li><a href="#"><i class="fa fa-cog" aria-hidden="true"></i> <?php echo $lang ['SETTINGS']; ?></a></li>
<li class="divider"></li>
<li><a href="#"><i class="fa fa-sign-out" aria-hidden="true"></i> <?php echo $lang ['SIGN-OUT']; ?></a></li>
</ul>
</li>
Upvotes: 0
Views: 109
Reputation: 1568
I solved the menu problem this way:
insted of add
include_once("menu.php");
I included the menu code direct in the page. The redirect problem I solved using javascript, insted of
header("Location: page.php)";
I did this
<?php
echo'<script> window.location = "page.php";</script>';
?>
Upvotes: 0
Reputation: 9782
The RewriteConds check if the request URL is a file, directory or symlink, and if so (the default is AND), the first rewrite will fail.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^([a-z0-9-_.]+)/?$ index.php?id=$1 [NC,L]
RewriteRule ^([a-z0-9-_.]+)/([a-z0-9]+)/?$ index.php?id=$1&goto=$2 [NC,L]
If it is a page like settings.php, the second rule will also fail.
Upvotes: 1