Change some URLs with leading ?

Discuss practical ways rearrange URLs using mod_rewrite.

Change some URLs with leading ?

Postby waro » Thu Aug 28, 2008 6:21 am

I have a bunch of URL formats that I'd like to make them search engine friendly. They are, for example:

http://localhost/?show=media&cid=1
http://localhost/?show=pages&cid=1&pages_id=2&detail

I tried to use this .htaccess code below but it didn't work.

Code: Select all
RewriteEngine On
RewriteBase /ms
Options +FollowSymLinks

RewriteRule ^([^/]+)/$ ?show=$1
RewriteRule ^([^/]+)/([0-9]+)/$ ?show=$1&cid=$2
RewriteRule ^([^/]+)/detail/([0-9]+)/([0-9]+)/$ ?show=$1&cid=$2&pages_id=$3&detail=1
RewriteRule ^gallery/detail/([0-9]+)/([0-9]+)/$ ?show=gallery&cid=$1&gallery_id=$2&detail=1
RewriteRule ^polling/result/([0-9]+)/([0-9]+)/$ ?show=polling&cid=$1&polling_id=$2&results=1
RewriteRule ^polling/vote/([0-9]+)/([0-9]+)/$ ?show=polling&cid=$1&polling_id=$2&votes=1
RewriteRule ^gallery/image-detail/([0-9]+)/([0-9]+)/([0-9]+)/$ ?show=gallery&cid=$1&gallery_id=$2&gallery_images_id=$3&detail=1
RewriteRule ^artist/detail/([0-9]+)/$ ?show=artist&pages_id=$1&detail=1
RewriteRule ^news/comment/([0-9]+)/edit/$ ?show=comments&comment_id=$1&edit=1&stype=news
RewriteRule ^news/comment/([0-9]+)/delete/$ ?show=comments&comment_id=$1&delete=1&stype=news
RewriteRule ^albums/comment/([0-9]+)/edit/$ ?show=comments&comment_id=$1&edit=1&stype=albums
RewriteRule ^albums/comment/([0-9]+)/delete/$ ?show=comments&comment_id=$1&delete=1&stype=albums


I'm sure that mod_rewrite is working, as I test it using a simple redirect rule such as:

Code: Select all
RewriteRule ^index\.php index.html


in other directory, and it worked fine.

I'm guessing that the problem is in the rewrite rules, but I ran out ideas to find the solution. I tried to google, and read a bunch of articles and postings with no luck. I even tried to generate the rules using an online rewrite generator, but still doesn't work.

Thanks in advance.
waro
 
Posts: 4
Joined: Thu Aug 28, 2008 5:50 am

Postby richardk » Fri Aug 29, 2008 7:55 am

What happens when you go to /media/1/?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]+)/$ /?show=$1 [QSA,L]

RewriteRule ^([^/]+)/([0-9]+)/?$ /?show=$1&cid=$2 [QSA,L]
RewriteRule ^([^/]+)/detail/([0-9]+)/([0-9]+)/?$ /?show=$1&cid=$2&pages_id=$3&detail=1 [QSA,L]
RewriteRule ^gallery/detail/([0-9]+)/([0-9]+)/?$ /?show=gallery&cid=$1&gallery_id=$2&detail=1 [QSA,L]

RewriteRule ^polling/(result|vote)/([0-9]+)/([0-9]+)/?$ /?show=polling&cid=$2&polling_id=$3&$1s=1 [QSA,L]

RewriteRule ^gallery/image-detail/([0-9]+)/([0-9]+)/([0-9]+)/?$ /?show=gallery&cid=$1&gallery_id=$2&gallery_images_id=$3&detail=1 [QSA,L]
RewriteRule ^artist/detail/([0-9]+)/?$ /?show=artist&pages_id=$1&detail=1 [QSA,L]

RewriteRule ^(albums|news)/comment/([0-9]+)/|delete|edit)/?$ /?show=comments&stype=$1&comment_id=$2&$3=1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

didn't wor

Postby waro » Sat Aug 30, 2008 2:27 am

unfortunately it didn't work
I'm stIll got the 500 error.

thank you anyway.
waro
 
Posts: 4
Joined: Thu Aug 28, 2008 5:50 am

Postby richardk » Sat Aug 30, 2008 11:23 am

Code: Select all
^(albums|news)/comment/([0-9]+)/|delete|edit)/?$

should be
Code: Select all
^(albums|news)/comment/([0-9]+)/(delete|edit)/?$


If you still get a 500 error try removing the Options line. Also look in your error log.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby waro » Sat Aug 30, 2008 6:05 pm

I don't get the 500 error but it's not working either. If you will, please visit my test site at http://ms.tokoq.com/.

Logically, I understand the script.. but I don't know how that it doesn't work.

Thanks.
waro
 
Posts: 4
Joined: Thu Aug 28, 2008 5:50 am

Postby richardk » Sun Aug 31, 2008 8:50 am

The mod_rewrite is working (go to http://ms.tokoq.com/albums/8). Mod_rewrite does not change the links in the source of your page, you must edit your script to output the new URLs.

To get your CSS, JavaScript and images to work, see: Relative paths to images, JavaScript, CSS and other external/linked files are broken.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby waro » Mon Sep 01, 2008 5:13 pm

:) silly me.. and I thought mod_rewrite magically change links in my source...

thank you for point it out...
waro
 
Posts: 4
Joined: Thu Aug 28, 2008 5:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 21 guests

cron