Jump to content
Larry Ullman's Book Forums

ReWriteRule works but occasionally shows the variables in URL?

Recommended Posts


My htaccess has a this ReWriteRule which works perfectly:

RewriteRule ^browse/([A-Za-z\+\-]+)/([A-Za-z\+\-]+)/?$ browse.php?type=$1&category=$2

However sometimes I see the variables included in the URL bar.

Other links are fine:

I cant tell why only a few select links show the variables.

Any help would be appreciated.

Here is my full htaccess file - some bits added for SEO:

<if "%{HTTPS} == 'on'">
  Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"

ErrorDocument 404 /404.php

<IfModule mod_rewrite.c>
Options -MultiViews

## Base Redirects ##

# Turn on Rewrite Engine
RewriteEngine On

# Redirect to secure HTTPS before changing host
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteCond %{https} off 
RewriteRule ^(.*)$ https://mysite.com/$1 [R=301,L]

# Remove trailing slash from non-filepath urls
RewriteCond %{REQUEST_URI} /(.+)/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ https://www.mysite.com/%1 [R=301,L]

# Include trailing slash on directory 
RewriteCond %{REQUEST_URI} !(.+)/$
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)$ https://www.mysite.com/$1/ [R=301,L]

# Force HTTPS and WWW 
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [OR,NC]
RewriteCond %{https} off 
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R=301,L]

# For product categories:
RewriteRule ^browse/([A-Za-z\+\-]+)/([A-Za-z\+\-]+)/?$ browse.php?type=$1&category=$2

# For specific product:
RewriteRule ^products/([A-Za-z\+\-]+)/([0-9a-zA-Z-]+)/?$ products.php?category=$1&SEOpagename=$2

Link to post
Share on other sites

ok - now I see that it is just the last link in each of my drop down menu lists that show the variables in the URL bar when clicked?

The links look EXACTLY the same to the other links in the drop down menu (dynamically created).

Any ideas anyone?  Im going around in circles here...

Here is the html of a drop down menu - the highlighted link shows the variables once clicked? (its always the last link that does this)

<ul class="menu photo-dropdown submenu is-dropdown-submenu first-sub vertical js-dropdown-active" data-submenu="" role="menu" style="">
    <li class="cell is-submenu-item is-dropdown-submenu-item" role="menuitem">
        <a href="/browse/off-road/worklights/">
            <img src="/products/menu_work_light.jpg" alt="Work Lights">
            <br>Work Lights</a>
    <li class="cell is-submenu-item is-dropdown-submenu-item" role="menuitem">
        <a href="/browse/off-road/lightbars/">
            <img src="/products/menu_lightbars.jpg" alt="Lightbars">

Link to post
Share on other sites

Hi David - sorry for the late response: Code is as follows

//fetch data
$r = mysqli_query($dbc, "SELECT * FROM categories WHERE master_category = 'on-road' ORDER by id;");

// create variable
$on_road_products_basic_menu = '';

//create links
while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC ) ) {
     if ( $r ) {

$on_road_products_basic_menu .= '<li>
                                        <a href="/browse/'.$row['master_category'].'/'.$row['category'].'/">

Link to post
Share on other sites

This is strange. There's nothing in your PHP code that would explain this. Could you confirm the exact sequence of events and the result? So you're on a page with what specific URL? And then you click what specific link (and what is that specific URL)? And then the resulting URL is what?

Link to post
Share on other sites

Hi Larry,

You can view yourself - the site is live:

If you select the (for eg) "On Road Lights" and then choose one of the drop down menu links:

All the menu links EXCEPT the last menu link will link correctly:

Ie: The resultant page will open and the link will display:


However - the last menu item in this drop down - in our case "Round Driving Lights", when clicked, will show:


This is the same across all the product menu items.

I'm stumped.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...