1,105,242 Community Members

url rewriting

Member Avatar
rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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 random text and still page is generated, and some of the keys are mixed, like say for first (.) i have given key a1 which is to be used in combination with a2,a3 and a4 (url keys of second,third and fourth(.*)) , but now a1 is used in combination with other url keys say b2 and c3 also

LastMitch
Deleted Member
 
0
 

@rohanbajaj222

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 random text and still page is generated, and some of the keys are mixed, like say for first (.) i have given key a1 which is to be used in combination with a2,a3 and a4 (url keys of second,third and fourth(.*)) , but now a1 is used in combination with other url keys say b2 and c3 also

RewriteRule (.)/(.)/mcqs/(.)/(.)/(.*).html mcq.php?mcq_id=$4&page=$5

If you want to create or try to create a URL rewrite then read and follow the instructions:

http://www.cyberdesignz.com/blog/website-design/url-rewriting-top-5-ways-of-php-url-rewriting/

or

Try to used this Mod Rewrite Generator:

http://www.generateit.net/mod-rewrite/

Member Avatar
rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

As my url keys are coming from db, so none of the above 2 links are helpful

LastMitch
Deleted Member
 
0
 

@rohanbajaj222

As my url keys are coming from db, so none of the above 2 links are helpful

What are the table(s)?

Member Avatar
rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

u mean table structure.?

Member Avatar
rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

id-primary key subcat_id - from home page mcq_head- mcq heading enabled -0/1 keywords-appearing on page for seo keyword_tag - url key meta_tag- meta keywords content_tag- meta content description page_title -page title

LastMitch
Deleted Member
 
0
 

@rohanbajaj222

RewriteRule (a1)/(a2)/mcqs/(a3)/(a4)/(.*).html mcq.php?mcq_id=$4&page=$5 

I have never seem a RewriteRule like that before?

Maybe something like this I have seen:

RewriteRule ^/mcqs/([^/]*)/([^/]*)/([^/]*)/([^/]*).html mcq.php?mcq_id=$1&subcat_id=$2 [L]  

I am very confused what you are trying to accomplish here.

You're id's is very confusing!

Something like this (make more sense):

RewriteRule ^mcq_id-([0-9]+)/subcat_id-([0-9]+)$  mcq.php?mcq_id=$1&subcat_id=$1 [L]

What I did I passed 2 variable into mcq.php. You can add as many as you want.

The reason why when you click on a link or item. It will go to that url (mcq.php?mcq_id=$1&subcat_id=$1) link.

Member Avatar
rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
actually structure of site is 
home page---> categories---->subcategories---->Mcqs headings--->sub heading 1
                                          |                 |
                                          |                 |
                                          |                 sub heading 2
                                          Non mcq
                for every category , subcategory, mcq heading and sub heading a url key is given                          
LastMitch
Deleted Member
 
0
 

@rohanbajaj222

actually structure of site

Is this a Ecommerce website?

The structure you have is not going work well:

RewriteRule (.)/(.)/mcqs/(.)/(.)/(.*).html mcq.php?mcq_id=$4&page=$5

I have seen 1 url key and try it before but I have never seen 4 url keys at once?

4 url keys at once in a Mod Rewrite? I'm not sure it's gonna work.

It would be much easier just write query for those ids and fetch them instead of using URL rewrite.

Member Avatar
rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

4 url keys are working, the only problem am facing is that any static text can be inserted in url and still page is displayed, and urls are taking other keys also say ,a3 is to be used a4, but now a3 is used b4 and c4 also (error), and a1 and a2 are used in combination with b3 and c4 (error)also

LastMitch
Deleted Member
 
0
 

a3 is to be used a4, but now a3 is used b4 and c4 also (error), and a1 and a2 are used in combination with b3 and c4 (error)also

Even though you got it working but its not working correctly.

You wrote a Mod Rewrite for this:

RewriteRule (.)/(.)/mcqs/(.)/(.)/(.*).html mcq.php?mcq_id=$4&page=$5

Maybe this works only once:

You insert a1 to a2 so it becomes a2.

But it's not gonna work for the rest as you notice yourself the errors you are having.

If you think that you can used 4 url keys at once and without any errors then keep trying.

From my point of view, it's not going to work well.

The purpose of Mod Rewrite is to make sure people can access your website by a particular page or page(s) which you can used any url keys but not 4 at once.

I really don't know what else to tell you.

Member Avatar
rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i own this site, coding done by programmer, can u help me in solving this problem, will provide u with details further

LastMitch
Deleted Member
 
0
 

can u help me in solving this problem, will provide u with details further

What URL do you need?

Member Avatar
rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

want to shorten the length of urls, reduce number of url heys from htaccess, and validate urls means if some random text is inserted in address bar , it should display msg as invalid url

LastMitch
Deleted Member
 
0
 

@rohanbajaj222

want to shorten the length of urls, reduce number of url heys from htaccess, and validate urls means if some random text is inserted in address bar , it should display msg as invalid url

Is this a Ecommerce website?

I mean you are doing alot of different urls.

I think I already mention to you that the purpose Mod Rewrite is to make sure people can access your website by a particular page or page(s).

Try to used this Mod Rewrite Generator:

http://www.generateit.net/mod-rewrite/

I copy and paste the example from the page link I provide:

For example, you may enter the URL:

youdomain/cgi-bin/shop.php?cmd=product&category=vehicles&product=bus

and transform it into

youdomain/shop/vehicles/bus.html

Do you understand how it works now?

Member Avatar
rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

no ,its not an ecommerce site,its an educational site
problem is that i have url keys coming from db , so cant shorten it with the help of link u provided
my gmail id is same as my userid here

LastMitch
Deleted Member
 
0
 

@rohanbajaj222

problem is that i have url keys coming from db , so cant shorten it with the help of link u provided

OK this is your current Mod Rewrite:

RewriteRule (.)/(.)/mcqs/(.)/(.)/(.*).html mcq.php?mcq_id=$4&page=$5

Add this to your htaccess file and try this:

RewriteEngine on
RewriteRule ^/mcqs/([^/]+)/([^/]+)\.html /mcq.php?mcq_id=$1&page=$2 [NC,R]

or try this:

RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/mcqs/([^/]+)/([^/]+)\.html /mcq.php?mcq_id=$1&page=$2 [NC,R]

If you want to see what I did read this:

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritemap

You have to play around with it. I don't have any url keys nor a database.

Do you have query to fetch the url id?

Member Avatar
rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I tried with
RewriteRule ^([^/]+)/([^/]+)/mcqs/([^/]+)/([^/]+).html /mcq.php?mcq_id=$1&page=$2 [NC,R]
as am having 2 url keys before mcqs, but didnt worked
404 error was displayed

LastMitch
Deleted Member
 
0
 

as am having 2 url keys before mcqs, but didnt worked

If this is new website there shouldn't be any error at all.

Is your website active?

If it's active you need to create 404 error page so it can redirected to the pages.

Without it, it won't redirected.

You need to add these to your htaccess file:

DirectoryIndex index.php
ErrorDocument 404  /error.php 

Redirect /olddirectory yourdomain/newdirectory
Member Avatar
rohanbajaj222
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

ya its active, not new, i have 404 page
and after writing rewrite rule 404 page was displayed
http://www.avatto.com/gate/aptitude/mcqs/reasoning/complete-the-series/104/1.html
this is the url I was talking about

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: