0

Hey,

I have all pages in my site, coming from the DB, and I get urls like this:

enkeltwebdesign/index.php?sid=1&titel=FORSIDE

The name of my site:

enkelt-webdesign.dk

Does someone know how to write the correct mod_rewrite, so I can change the urls to:

enkelt-webdesign.dk/forside (forside = home)
enkelt-webdesign.dk/webdesign (...)
etc etc

So I want to get rid of:
index.php?sid=1&titel=
And only pass this to the url: /forside

It is urgent, so I hope someone sees this as childs play, as I have never before made any regex related to Apache.

Thank you, I hope to hear from you

Regards, Klemme

Edited by klemme: n/a

2
Contributors
15
Replies
17
Views
6 Years
Discussion Span
Last Post by klemme
0

You must put it in .htaccess file.

RewriteEngine On
      RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?sid=1&titel=$1
      RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?sid=1&titel=$1

Edited by digwnews: n/a

0

Thank you for your answer!

I have this in my .htacess file:
(The hosting company had some code there, which I dont know how to translate?)
But I didnt delete any of it just in case.

# -FrontPage-

# IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
RewriteEngine On
      RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?sid=1&titel=$1
      RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?sid=1&titel=$1

But nothing happens at all, the urls still look the same.

Any idea how this can be??

0

I am currently tjecking it on my localhost, but I guess I should get the same error there?

But no errors, and no result yet.

I can try to upload it, and see if there is an error specified.

0

Just uploaded it to the real site, and nothing happens at all?

No errors either!

My host has got rewrite activated, so it should be able to run if correct!??

Edited by klemme: n/a

0

I misunderstud you before!

When i write:

enkelt-webdesign.dk/forside

It works!

BUT only for that one page.

I need to get exactly that urls after a LINK is clicked - cause when a linked is clicked, the ugly urls are right back? :-)

Edited by klemme: n/a

0

Yeah I guess it is called redirect!

So when the link which is build like this, is clicked:

<a href="index.php?sid=' . $sid . '&amp;titel='.$linknavn.'">' . $subjectlinklabel . '</a>

it looks "ugly" in the url,

And I would like it so only this is seen in the url:

enkelt-webdesign.dk/forside
enkelt-webdesign.dk/seo
enkelt-webdesign.dk/hosting

so only the site name, and /forside

so leaving out(in bold): index.php?sid=1&titel=forside

etc etc

Thats is called a redirect?

Forgive me on this part.. :-)

Edited by klemme: n/a

0

Okay so now i have the following - but it didnt change it though.

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?sid=1&titel=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?sid=1&titel=$1
RedirectMatch ^index\.php\?sid=(.*)&titel=(.*)$ http://enkelt-webdesign.dk/$2

isnt there sometimees used something like

follow sys...?

Edited by klemme: n/a

0

Well good question :-)

I can show you how I have build the navigation.

Everything is database driven: (And I dont know how else to make this work)

function general_navigation($connection){
$subjectset = mysqli_query($connection, "SELECT id, titel, linknavn FROM subjects ORDER BY pos ASC");
   while($subject = mysqli_fetch_array($subjectset)){
   $linknavn = $subject['linknavn'];
   $sid = $subject['id'];
   $subjectlinklabel = $subject['linknavn'];
 
echo '<br /><li><a href="index.php?sid=' . $sid . '&amp;titel='.$linknavn.'">' . $subjectlinklabel . '</a></li>';

I dont know how else to create the navigation, other than passing the id for identifying the row, and then use the title in the link/url?

So this is the reason that I need to do some mod_rewrite/redirect :-)

0

I am not sure it is a redirect, is it?

When I want to get rid of the querystring, and only keep the title in the querystring?

Mod_rewrite (QUERYSTRING)... (just written correctly..)

?

Edited by klemme: n/a

0

I was shown this bit of code, and told that it could do what i am asking.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule .* index.php [L]

And then I need to parse the $_SERVER

What and how could that be done, anyone knows how to pass the $_SERVER, to make the above mod_rewrite work?

I am helpless on this topic!

Edited by klemme: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.