codeFragment
codeFragment

Reputation: 103

.htaccess redirect with a variable?

I need your help.

I want to redirect a URL like:

http://test.mydomain.com/tag/4

to

http://test.mydomain.com/tag/tag.php?id=4

The number is a variable and can change of course. Hope you have a solution for me.

    RewriteEngine On
    RewriteBase /tag

    and now?..

I'm a total newbie in .htaccess!

Thanks for your short help

Upvotes: 0

Views: 62

Answers (1)

user1994997
user1994997

Reputation:

Simply add this line to your .htaccess file

Redirect 301 http://test.mydomain.com/tag/4 http://test.mydomain.com/tag/tag.php?id=4

This is best done using the pages path. Here's an example:

Redirect 301 /tag/4.html http://test.mydomain.com/tag/tag.php?id=4

This should give you all you need http://www.htaccessredirect.co.uk/

Given that you're talking about redirection from said page using what the user types: Create a text box and a button like this <button onclick="redit();">

Then add this function

<script type="text/javascript">
    function redir(){
       var page = document.getElementById("textArea").value;
       location.href = "http://test.mydomain.com/tag/tag.php?id=" + page;
    };
</script>

This will send the user to the page you want them to, based on what they selected as page number.

Upvotes: 1

Related Questions