Jump to content
Larry Ullman's Book Forums
Hillbilly

ReWriteRule works but occasionally shows the variables in URL?

Recommended Posts

Hi,

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.
Eg:
https://www.mysite.com/browse/on-road/lights?type=on-road&category=lights

Other links are fine:
https://www.mysite.com/browse/on-road/worklights

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"
</if>

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
</IfModule

Share this post


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>
    <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">
            <br>Lightbars</a>
    </li>                    
</ul>

Share this post


Link to post
Share on other sites

HI,

 

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

 

can you provide the php code for this ?

Regards

David

Share this post


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'].'/">
                                        '.$row['display_name'].'</a>
                                        </li>';
}
}

Share this post


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?

Share this post


Link to post
Share on other sites

Hi Larry,

You can view yourself - the site is live:
www.ltprtz.co.uk

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:

/browse/on-road/headlights

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

/browse/on-road/driving-round-lights?type=on-road&category=driving-round-lights

This is the same across all the product menu items.

I'm stumped.

Share this post


Link to post
Share on other sites

Hi,

 

I have tested the site live and its all working my end.

It may be obvious but  your cache on your browser may be causing this, clear your browser cache and try another browser, also, are you testing locally or on the live site ?

Regards

David

Share this post


Link to post
Share on other sites

Perfect! I should have tried that first and saved myself alot of effort!

I was testing on both IE and Chrome and both were giving the same issues - now cleared.

(Site was already live when the issues showed up)

Thank you for your input. Now my mind is at ease.

Share this post


Link to post
Share on other sites

Glad to hear you got it sorted!

As a side note, when developing its good to test your site on 4 -5 different browsers (Firefox being my favorite) as they all behave differently, most noticeably IE.

Nice color theme by the way !

Share this post


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.

Guest
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.

Loading...

×
×
  • Create New...