We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,623 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion
Page 2 of Article: url rewriting
my url keys are coming from database , say if my url is abc.com ,i have used a rewrite rule RewriteRule (.*)/(.*)/mcqs/(.*)/(.*)/(.*)\.html mcq.php?mcq_id=$4&page=$5 in this rewrite rule , first four (.*) are coming as url keys from db, but problem is that in address bar am able to add any…

and after writing rewrite rule 404 page was displayed

How many sections?

Is this your table structure?

id
subcat_id
mcq_head
enabled
keywords
keyword_tag
meta_tag
content_tag
page_title

What is the url here:

You said 4 url?

This is only 2:

mcq_id=0&page=0

How does it look:

from 4 to 3 to 2 to 1

LastMitch
Industrious Poster
4,374 posts since Mar 2012
Reputation Points: 149
Solved Threads: 350
Skill Endorsements: 47

yes , this is the table structure for mcqs.
In this url
http://www.avatto.com/gate/aptitude/mcqs/reasoning/complete-the-series/104/1.html
I said there are 4 url keys one each for
1. home page category -eg gate
2. home page subcategory-eg aptitude
3. mcq head category-eg reasoning
4. mcq subheading -eg complete-the-series

later on home page categories and subcategories have to be changed , but couldnt change the url keys, as those were indexed by google

rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

@rohanbajaj222

later on home page categories and subcategories have to be changed , but couldnt change the url keys, as those were indexed by google

There's nothing wrong with your URL's.

I think it's your query that fetch the url key is incorrect so that's why it's not displaying the url keys.

LastMitch
Industrious Poster
4,374 posts since Mar 2012
Reputation Points: 149
Solved Threads: 350
Skill Endorsements: 47

hum......., am using this query

$QUERY="select tbl_mcq_title.id, tbl_mcq_title.mcq_title, tbl_category_master.category_name, tbl_subcategory_master.subcat_name, tbl_mcq_master.mcq_head, tbl_category_master.keywords as cat_key, tbl_subcategory_master.keywords as subcat_key, tbl_mcq_master.keywords as head_key, tbl_mcq_title.keywords as title_key from tbl_mcq_title left join tbl_mcq_master on tbl_mcq_title.mcq_m_id = tbl_mcq_master.id join tbl_subcategory_master on tbl_subcategory_master.id = tbl_mcq_master.subcat_id join tbl_category_master on tbl_category_master.id = tbl_subcategory_master.cat_id WHERE tbl_subcategory_master.id=$subcat_id order by tbl_mcq_master.mcq_head, tbl_mcq_title.mcq_title"

for displaying
http://www.avatto.com/gate/computer-science/mcqslist/10.html

rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

@rohanbajaj222

You're query is a JOIN.

Try this I'm not sure it's gonna work because in order to test out URL you have to test it:

//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^avatto.com[nc]
RewriteRule ^(.*)$ http://www.avatto.com/$1 [r=301,nc]

//301 Redirect Entire Directory
RedirectMatch 301 www.avatto.com(.*) www.avatto.com/$1

//Change default directory page
DirectoryIndex www.avatto.com

//Rewrite 1
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^([^/]+)/([^/]+)/mcqs/([^/]+)/([^/]+).html$ $mcq.php?mcq_id=$1&page=$2 [NC,R]

//Rewrite 2
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^(.*)/(.*)/mcqs/(.*)/(.*).html$ $mcq.php [R=301,L]
LastMitch
Industrious Poster
4,374 posts since Mar 2012
Reputation Points: 149
Solved Threads: 350
Skill Endorsements: 47

it didnt worked, i got internal server error

rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

What error?

LastMitch
Industrious Poster
4,374 posts since Mar 2012
Reputation Points: 149
Solved Threads: 350
Skill Endorsements: 47

error message was internal server error

rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

I think i sent wrong query, tht was from another site

rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

I think i sent wrong query, tht was from another site

I create 2 Rewrite:

//Rewrite 1
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^([^/]+)/([^/]+)/mcqs/([^/]+)/([^/]+).html$ $mcq.php?mcq_id=$1&page=$2 [NC,R]
//Rewrite 2
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^(.*)/(.*)/mcqs/(.*)/(.*).html$ $mcq.php [R=301,L]

I think the issue was I put 2 rewrite that is the same that made the internal error.

This code should be in the htaccess file try this:

//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^avatto.com[nc]
RewriteRule ^(.*)$ http://www.avatto.com/$1 [r=301,nc]
//301 Redirect Entire Directory
RedirectMatch 301 www.avatto.com(.*) www.avatto.com/$1
//Change default directory page
DirectoryIndex www.avatto.com
//Rewrite 1
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^([^/]+)/([^/]+)/mcqs/([^/]+)/([^/]+).html$ $mcq.php?mcq_id=$1&page=$2 [NC,R]

then try this if the first one didn't work:

//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^avatto.com[nc]
RewriteRule ^(.*)$ http://www.avatto.com/$1 [r=301,nc]
//301 Redirect Entire Directory
RedirectMatch 301 www.avatto.com(.*) www.avatto.com/$1
//Change default directory page
DirectoryIndex www.avatto.com
//Rewrite 2
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^(.*)/(.*)/mcqs/(.*)/(.*).html$ $mcq.php [R=301,L]
LastMitch
Industrious Poster
4,374 posts since Mar 2012
Reputation Points: 149
Solved Threads: 350
Skill Endorsements: 47

I tried both of them very carefully, but none of them is helping out.
Thanx for help

rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

I tried both of them very carefully, but none of them is helping out.
Thanx for help

I can't think of another way of doing this. The only way is to really test the Mod Rewrite on your host server.

You already have Data on your database. I don't have a db but you did provide a table but it's much harder for me to duplicate the data and test out the Mod Rewrite.

I know you been trying to make this work but it's much easier to ask your developer(s) to do the Mod Rewrite for you.

LastMitch
Industrious Poster
4,374 posts since Mar 2012
Reputation Points: 149
Solved Threads: 350
Skill Endorsements: 47

i have another problem also, if i insert some static text in my urls from browser , they are not redirected to their original url , nor do they show some error, do we solve this problem from htaccess or chenges in db are required

rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

they are not redirected to their original url , nor do they show some error, do we solve this problem from htaccess or chenges in db are required

Yes, you can solve the issue in the htaccess file by writing this:

Read this and try the examples:

http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/

http://www.simonecarletti.com/blog/2009/01/apache-rewriterule-and-query-string/

LastMitch
Industrious Poster
4,374 posts since Mar 2012
Reputation Points: 149
Solved Threads: 350
Skill Endorsements: 47

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.1047 seconds using 2.86MB