Friendly URLs

Discuss practical ways rearrange URLs using mod_rewrite.

Friendly URLs

Postby Magnusson » Wed May 13, 2009 1:50 am

Friendly URLs

Hello,

I need help to write some rewrite rules in the .htaccess file for a site of mine. The things I want to do is:

first set of rules:
http://www.x.com/this-is-text_1/
->
http://www.x.com/index.php?id=1

second:
http://www.x.com/sok_hej/
->
http://www.x.com/index.php?sok=hej

I would be very thankful if I could get some help doing this.
Magnusson
 
Posts: 18
Joined: Thu Oct 12, 2006 12:35 pm

Postby richardk » Wed May 13, 2009 7:46 am

Does sok change?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^sok_([^/]+)/?$    /index.php?sok=$1 [QSA,L]
RewriteRule ^[^/]+_([0-9]+)/?$ /index.php?id=$1  [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Magnusson » Mon May 18, 2009 10:26 am

First thanx for the thelp! Sok vill never change so another example is:
http://www.x.com/sok_whatever/
->
http://www.x.com/index.php?sok=whatever

I have my account at one.com and it already contains a .htaccess file.

Code: Select all
# -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>


so when I add this code after the code above
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^sok_([^/]+)/?$    /index.php?sok=$1 [QSA,L]
RewriteRule ^[^/]+_([0-9]+)/?$ /index.php?id=$1  [QSA,L]


I get the following error message when I try to load the page

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, support@one.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
Magnusson
 
Posts: 18
Joined: Thu Oct 12, 2006 12:35 pm

Postby richardk » Mon May 18, 2009 11:12 am

What does your error log say is causing the error?

Try removing
Code: Select all
Options +FollowSymLinks
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Magnusson » Tue May 19, 2009 3:46 pm

Hi,

it wasnt the error log. I got the error in the browser when I tried to access the page. But when I removed "Options +FollowSymLinks" it worked! :) Thank you richardk!
Magnusson
 
Posts: 18
Joined: Thu Oct 12, 2006 12:35 pm

Postby richardk » Tue May 19, 2009 3:49 pm

it wasnt the error log. I got the error in the browser when I tried to access the page.

You get more information about 500 (Internal Server) errors if you look at the error log file. You may or may not have access to the error log, it might be accessible through your control panel.
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, support@one.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 23 guests

cron