I was asked to help a friend to rewrite urls for a site he has a client.

The link structure looks like this:

<a href="http://sitename.dk/index.php?page=wisetrap">WiseTrap</a>
// URL: sitename.dk/index.php?page=wisetrap

Is it possible to keep the link structure like that, but after the link is clicked make it appear in the url like this:

// URL: sitename.dk/wisetrap

Any htaccess brains out there?

I know I have to deal with some variables in the htaccess file, but I havent been able to make it work.

So basicaly strip the filename: index.php and then add the 1.st $_GET variable to the end..


Recommended Answers

All 5 Replies

Thanks for your answer!

It gave me this url:

// I created a test page, and have links like this:

<a href="index.php?page=grise">grise</a>
<a href="index.php?page=hunde">hunde</a>
<a href="index.php?page=fugle">fugle</a>
<a href="index.php?page=heste">heste</a>
<a href="index.php?page=slanger">slanger</a>

// I adde this to the htaccess file:
RewriteRule (.*) http://www.sitename.dk/index.php?page=$1 [QSA,L]

// And got this url:

// And im after:

Any idea?

Sorry, I missed the bit about redirect to the new URL structure.

RewriteEngine On
RewriteRule ^index\.php?page=(.*) http://www.sitename.dk/$1 [R=301,QSA,L]

Hmm, that didnt do anything at all, guess im doing something wrong..

Could I do this, and not use any domain name in the rewrite:

RewriteRule ^index\.php?page=(.*) index\.php/$1 [R=301,QSA,L]

That is also not doing anything, but you get the idea?

Member Avatar
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/*$ index.php?page=$1 [L]

Just a rewrite not a redirect. So for that your links would have to be in the rewritten format too.

<a href="/slanger/">slanger</a>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.