LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 12-22-2011, 12:12 AM   #1
dazzler20
LQ Newbie
 
Registered: Dec 2011
Location: Hyderabad
Distribution: Ubuntu 10.10
Posts: 7

Rep: Reputation: Disabled
htaccess url rewriting but page is not getting displayed


Hi all,

i am very new to url re-writing using htaccess..

i had googled and made found to below code(made changes to it)


i want to re-write the below url
http://localhost/sai/project/product...e=harrypotter5

to

http://localhost/sai/project/books/h...ter5/7174.html

I'm a newbie in htaccess..please help me to sort it
 
Old 12-22-2011, 12:48 AM   #2
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Hello and welcome to LinuxQuestions,

Although your posts are not 'copy/pasted' double-posting is against the LQ policy. Posting your problem in more then one forum will only confuse you and us and loose track of the conversation. Stick to this thread.

Reported the other thread as double-post.

Looking forward to your participation in the forums. Have fun with Linux.

Kind regards,

Eric
 
Old 12-22-2011, 02:41 AM   #3
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,884

Rep: Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322
Quote:
i had googled and made found to below code(made changes to it)
I don't see any code
Anyway, try this:
Code:
RewriteEngine On
RewriteBase /sai/project
RewriteCond %{QUERY_STRING} name=(.*)&&productid=(.*)
RewriteRule productpage.php(.*) books/%1/%2.html?
Regards
 
Old 12-22-2011, 04:00 AM   #4
dazzler20
LQ Newbie
 
Registered: Dec 2011
Location: Hyderabad
Distribution: Ubuntu 10.10
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thank you bathory for quick reply...i had copied the line in .htaccess in my project folder...

when i click on the product for details...its showing "Object not found!" and the url is not getting changed;

Can you please make it work ..?
 
Old 12-22-2011, 05:47 AM   #5
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,884

Rep: Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322
Quote:
i had copied the line in .htaccess in my project folder...
Oups, I've made a mistake and reversed the order of the query parameters. So the correct should be:

RewriteEngine On
RewriteBase /sai/project
RewriteCond %{QUERY_STRING} productid=(.*)&&name=(.*)
RewriteRule productpage.php(.*) books/%1/%2.html?
 
Old 12-22-2011, 06:01 AM   #6
dazzler20
LQ Newbie
 
Registered: Dec 2011
Location: Hyderabad
Distribution: Ubuntu 10.10
Posts: 7

Original Poster
Rep: Reputation: Disabled
No bathory...still the same problem

Object not found! amd url not getting changed...

But when i type
http://localhost/sai/project/product...tter/7172.html

instead of the below url..

http://localhost/sai/project/product...productid=7172

the page is getting displayed..without css,images and php database queries are missing
 
Old 12-22-2011, 06:39 AM   #7
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,884

Rep: Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322
What is the correct URL? From your 1st post, I thought it's
Code:
http://localhost/sai/project/productpage.php?productid=7174&&name=harrypotter5
I mean you have first the productid and then the name variable in your query.

So first you need to decide for the correct URL (the query you're trying to pass to the php page) and second add some giberish into the .htaccess to see if apache actually reads it.

If you want the rewritten URL to be visible in the browser address bar add a {R] at the end of the RewriteRule
Code:
RewriteRule productpage.php(.*) books/%1/%2.html? [R]

Last edited by bathory; 12-22-2011 at 06:44 AM. Reason: Additional info
 
1 members found this post helpful.
Old 12-22-2011, 06:44 AM   #8
dazzler20
LQ Newbie
 
Registered: Dec 2011
Location: Hyderabad
Distribution: Ubuntu 10.10
Posts: 7

Original Poster
Rep: Reputation: Disabled
My url is like this

http://localhost/sai/project/product...productid=7174

I had tried both the htaccess code given by you


RewriteCond %{QUERY_STRING} productid=(.*)&&name=(.*)
RewriteRule productpage.php(.*) books/%1/%2.html?


RewriteCond %{QUERY_STRING} name=(.*)&&productid=(.*)
RewriteRule productpage.php(.*) books/%1/%2.html?

But it doesnt getting worked
 
Old 12-22-2011, 06:47 AM   #9
dazzler20
LQ Newbie
 
Registered: Dec 2011
Location: Hyderabad
Distribution: Ubuntu 10.10
Posts: 7

Original Poster
Rep: Reputation: Disabled
hi bathory,


This time the url has changed..but object not found is the error
 
Old 12-22-2011, 07:20 AM   #10
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,884

Rep: Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322
Quote:
Originally Posted by dazzler20 View Post
hi bathory,


This time the url has changed..but object not found is the error
Then look at apache error_log and see what is the URL it's trying to access.
BTW make up your mind with the query you're trying to pass to php, because the order of the variables matters in the final URL.
 
Old 12-22-2011, 07:54 AM   #11
dazzler20
LQ Newbie
 
Registered: Dec 2011
Location: Hyderabad
Distribution: Ubuntu 10.10
Posts: 7

Original Poster
Rep: Reputation: Disabled
Dear bathory,

Thanks for your patience and support...75% succeeded..will post if any queries arise...


Thank you
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
URL Rewriting not working, .htaccess file in a subdirectory. vikram_cvk Linux - Software 1 12-29-2010 08:53 PM
URL Rewriting in htaccess hatchnet Linux - General 7 07-05-2010 05:57 PM
URL rewriting for sub-domain scls19fr Linux - Server 6 10-05-2008 11:56 PM
URL Rewriting mrpraveen.p Linux - Newbie 1 06-03-2008 07:07 AM
URL Rewriting getmeontop Linux - Newbie 1 04-02-2008 02:12 AM


All times are GMT -5. The time now is 08:54 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration