0

I have menu and there are some modal windows on my site that are hidden on default and appear when I click on particular menu item (simple .show() jquery function). Is it possible to use htaccess like this:

Default site URL: www.example.com

Menu 1 visible (function called) when URL: www.example.com/menu1/

So when there is subdirectory (not query string) in URL particular function is called. Is is possible at all?

Sorry for english.

1

3 Answers 3

1

Use that PHP script to redirect users to another page(you can use GET-parameters and a if-query to let compile other content):

<?php
header('Location: http://www.example.com/#');
?>

And use that to run a function:

window.onload = function() {
if(window.location.hash) {
    //Run your JS code here
}
}

IMPORTANT: The hashtag indicates the redirect

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for idea. I improved it a little bit - see my answer.
Nice work! I can't write in mod_rewrite, but I can understand the idea you have.
1

I find a solution just with php and .htaccess thanks to idea from miny1997.

index.php:

<?php
    if (isset($_GET['menu']))
    {
        switch ($_GET['menu'])
        {
            case 'menu1':
                // jquery script 1
                break;
            case 'menu2':
                // jquery script 2
                break;
        }
    }
?>

.htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?menu=$1 [L,QSA]

Comments

0

I don't use htaccess to alter the content of a page, but you can achieve what you're asking about with javascript. You can use the window.location variable to determine what subdirectory the page is in (see here: http://css-tricks.com/snippets/javascript/get-url-and-url-parts-in-javascript/ for more info).

Then you can control whether to use .show() function with basic simple if blocks.

2 Comments

But I have single page web (index.php) and when there is subdirectory in URL, 404 error appear. I need to redirect these subdirectories into base URL and call specific function.
In javascript, doesn't matter what happens in server. As far as it's concerned, if URL displays as directory, the code should be fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.